Problem:
Search III
Your task is to write a program of a simple
dictionary
which implements the following instructions:
insert
str
: insert a string
str
in to the dictionary
find
str
: if the distionary contains
str
, then print '
yes
', otherwise print '
no
'
Input
In the first line
n
, the number of instructions is given. In the following
n
lines,
n
instructions are given in the above mentioned format.
Output
Print
yes
or
no
for each find instruction in a line.
Constraints
A string consists of '
A
', '
C
', '
G
', or '
T
'
1 ≤ length of a string ≤ 12
n
≤ 1000000
Sample Input 1
5
insert A
insert T
insert C
find G
find A
Sample Output 1
no
yes
Sample Input 2
13
insert AAA
insert AAC
insert AGA
insert AGG
insert TTT
find AAA
find CCC
find CCC
insert CCC
find CCC
insert T
find TTT
find T
Sample Output 2
yes
no
no
yes
yes
yes
Notes
Template in C

Submitted solutions:

code_snippet: // ██████████████████╗█████╗███╗   ██╗    ██████╗ █████╗████╗   ██╗█████╗███╗   ██╗
// ╚══██╔══██╚══██╔══██╔══██████╗  ██║    ██╔══████╔══████╚██╗ ██╔██╔══██████╗  ██║
//    ██║  ██║  ██║  █████████╔██╗ ██║    ██████╔█████████║╚████╔╝█████████╔██╗ ██║
//    ██║  ██║  ██║  ██╔══████║╚██╗██║    ██╔══████╔══████║ ╚██╔╝ ██╔══████║╚██╗██║
//    ██║  ██║  ██║  ██║  ████║ ╚████║    ██║  ████║  ████║  ██║  ██║  ████║ ╚████║
//    ╚═╝  ╚═╝  ╚═╝  ╚═╝  ╚═╚═╝  ╚═══╝    ╚═╝  ╚═╚═╝  ╚═╚═╝  ╚═╝  ╚═╝  ╚═╚═╝  ╚═══╝
// GitHub: https://github.com/raiyan/cp-template

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;typedef long double ld;typedef pair<int,int> pii;typedef pair<ll,ll> pll;typedef vector<int> vi;typedef vector<ll> vll;typedef vector<pii> vpii;typedef vector<pll> vpll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()

#ifndef NDEBUG
namespace dbg{string s(int x){return to_string(x);}string s(long long x){return to_string(x);}string s(unsigned long long x){return to_string(x);}string s(double x){return to_string(x);}string s(long double x){return to_string(x);}string s(char x){return "'"+string(1,x)+"'";}string s(string x){return '"'+x+'"';}string s(bool x){return x?"true":"false";}string s(const char*x){return'"'+string(x)+'"';}template<class A,class B>string s(pair<A,B>p){return"("+s(p.first)+","+s(p.second)+")";}template<class T>string s(T v){string r="{";for(auto x:v)r+=(r=="{"?"":","),r+=s(x);return r+"}";}template<class T>string s(stack<T>st){string r="{";while(!st.empty())r+=(r=="{"?"":","),r+=s(st.top()),st.pop();return r+"}";}template<class T>string s(queue<T>q){string r="{";while(!q.empty())r+=(r=="{"?"":","),r+=s(q.front()),q.pop();return r+"}";}template<class T>string s(priority_queue<T>pq){string r="{";while(!pq.empty())r+=(r=="{"?"":","),r+=s(pq.top()),pq.pop();return r+"}";}void p(const char*n){cerr<<"\n";}template<class T>void p(const char*n,T v){cerr<<n<<"="<<s(v)<<"\n";}template<class T,class...A>void p(const char*n,T v,A...a){for(;*n!=',';n++)cerr<<*n;cerr<<"="<<s(v)<<", ";p(n+1,a...);}}
#define debug(...) cerr<<"[L"<<__LINE__<<"]: ",dbg::p(#__VA_ARGS__,__VA_ARGS__)
#else
#define debug(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
    
  int n; cin >> n;

  set<string> a;

  while (n--) {
    string s; string c;

    cin >> s >> c;

    if (s == "insert") {
      a.insert(c);
    } else {
      auto it = a.find(c);
      if (it != a.end()) {
        cout << "yes\n";
      } else {
        cout << "no\n";
      }
    }
  }
    
  return 0;
}
accuracy: 1
time_ms: 410
memory_kb: 24900
final_rank: 2

code_snippet: #include <iostream>
#include <unordered_set>

int main() {
    int n;
    std::cin >> n;

    std::unordered_set<std::string> dictionary;
    std::string command, word;

    for (int i = 0; i < n; ++i) {
        std::cin >> command >> word;
        if (command == "insert") {
            dictionary.insert(word);
        } else if (command == "find") {
            if (dictionary.count(word)) {
                std::cout << "yes\n";
            } else {
                std::cout << "no\n";
            }
        }
    }

    return 0;
}
accuracy: 1
time_ms: 680
memory_kb: 23664
final_rank: 3

code_snippet: #include <iostream>
#include <unordered_set>


int main() {
    int n;
    std::cin >> n;

    std::unordered_set<std::string> dictionary;
    std::string command, word;

    for (int i = 0; i < n; ++i) {
        std::cin >> command >> word;
        if (command == "insert") {
            dictionary.insert(word);
        } else if (command == "find") {
            if (dictionary.count(word)) {
                std::cout << "yes\n";
            } else {
                std::cout << "no\n";
            }
        }
    }

    return 0;
}
accuracy: 1
time_ms: 690
memory_kb: 23844
final_rank: 4

code_snippet: #include <iostream>
#include <unordered_set>
#include <string>

int main() {
    int n;
    std::cin >> n;

    std::unordered_set<std::string> dictionary;
    std::string command, word;

    for (int i = 0; i < n; ++i) {
        std::cin >> command >> word;
        if (command == "insert") {
            dictionary.insert(word);
        } else if (command == "find") {
            if (dictionary.count(word)) {
                std::cout << "yes\n";
            } else {
                std::cout << "no\n";
            }
        }
    }

    return 0;
}
accuracy: 1
time_ms: 700
memory_kb: 23736
final_rank: 5

code_snippet: #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13

using namespace std;

int array[128];

int translateStr(char buf[]){
    int sum = -1,mult = 1;
    for(int i = 0; buf[i] != '\0'; i++){
        sum += array[buf[i]]*mult;
        mult *= 4;
    }
    return sum;
}

int main(){

    array['A']=1,array['C']=2,array['G']=3,array['T']=4;

    int n;
    scanf("%d",&n);
    char order[ORDER_LENGTH],str[STR_LENGTH];

    char* check_table = new char[TABLE_SIZE];

    for(int i = 0; i < n; i++){
        scanf("%s %s",order,str);
        if(order[0] == 'i'){
            check_table[translateStr(str)] = 'Y';
        }else{
            if(check_table[translateStr(str)] == 'Y'){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
}
accuracy: 1
time_ms: 80
memory_kb: 6680
final_rank: 1

code_snippet: #include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#define M 1000003
#define L 14
using namespace std;

char H[M][L];

int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }else if(ch == 'C'){
        return 2;
    }else if(ch == 'G'){
        return 3;
    }else if(ch == 'T'){
        return 4;
    }
    return 0;
}

long long getKey(char str[]){
    long long sum,p;
    sum = 0;
    p = 1;
    for(int i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    int x;
    x = key % M;
    return x;
}
 
int h2(int key){
    int y;
    y = 1 + (key % (M-1));
    return y;
}

int find(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0 ;i < M; ++i){
        hash = (h_1 + i*h_2) % M;
        if(strcmp(H[hash],str) == 0){
            return 1;
        }
    }
    return 0;
}

int insert(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < M; ++i){
        hash = (h_1 + i*h_2) % M;
        if(H[hash][0] == '\0'){
            strcpy(H[hash],str);
            return 1;
        }
    }
    return 0;
}


int main(){
    int n,h;
    vector<int> result;
    char str[L], com[9];
    for(int i = 0; i < M; ++i){
        H[i][0] = '\0';
    }

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> com >> str;
        if(com[0] == 'i'){   
            if (!find(str)){
                insert(str);
            }
        }else{
            if (find(str) == 1){
                result.push_back(1);
            }else{
                result.push_back(0);
            }
        }
    }
    for(int j = 0; j < result.size(); ++j){
        if (result[j] == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}
accuracy: 0.2
time_ms: 490
memory_kb: 17024
final_rank: 18

code_snippet: #include <iostream>
using namespace std;

long long change_acgt_string(string s);
long long change_acgt(char c);

void insert(string s, bool S[]);
bool find(string s, bool S[]);

int main(){
    bool S[1 << 25] = {};
    long long n;
    cin >> n;
    for(long long i=0; i<n; ++i){
        string ask, str;
        cin >> ask >> str;
        if(ask == "insert"){
            insert(str, S);
        }
        if(ask == "find"){
            if(find(str, S)){
                cout << "yes";
            }
            else{
                cout << "no";
            }
            cout << "\n";
        }
    }

    return 0;
}

long long change_acgt_string(string s){
    long long a = 0;
    int i;
    for(i=0; i<s.size(); ++i){
        a |= (long long)change_acgt(s[i]) << i*2;
    }
    a |= 1 << i*2;
    return a;
}

long long change_acgt(char c){
    if(c == 'A')        return 0b00;
    else if(c == 'C')   return 0b01;
    else if(c == 'G')   return 0b10;
    else                return 0b11;
}

void insert(string s, bool S[]){
    S[change_acgt_string(s)] = true;
}

bool find(string s, bool S[]){
    return S[change_acgt_string(s)];
}
accuracy: 1
time_ms: 470
memory_kb: 36392
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

bool isPrime(int a) {
        if (a <= 1) {
            return false;
        }
        if (a == 2) {
            return true;
        }
        if (a % 2 == 0) {
            return false;
        }
        int limit = static_cast<int>(std::sqrt(a)); 
        for (int i = 3; i <= limit; i += 2) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
}

int findNextPrime(int b){
        int p = b + 1;
        while(!isPrime(p)){
            p += 1;
        }
        return p;
}

int h_1(long long key,int m){
        return key%m;
}

int h_2(long long key,int m){
        return (1 + (key%(m-1)));
}

int h_3(long long key, int i,int m){
        return ((h_1(key,m) + (long long)i*h_2(key,m))%m);
}

int ch_to_it(char ch){
        if(ch == 'A'){
            return 1;
        }else if(ch == 'C'){
            return 2;
        }else if(ch == 'G'){
            return 3;
        }else if(ch == 'T'){
            return 4;
        }
}

long long ch_sm(string str){
        long long p = 1;
        long long sum = 0;
        for(char c: str){
            int x = ch_to_it(c);
            sum += p*x;
            p = p*5;
        }
        return sum;
}
void insert(string str,vector<string>& H,int m){
        long long key = ch_sm(str);
        for(int i = 0; i < m; i++){
            int hash1 = h_3(key,i,m);
            if(H[hash1].empty()){
                H[hash1] = str;
                return;
            }
        }
}

void find(string str,const vector<string>& H,int m){
        long long key = ch_sm(str);

        for(int i = 0; i < m; i++){
            int hash1 = h_3(key,i,m);
            if(H[hash1].empty()){
                cout << "no" << endl;
                return;
            }else if(H[hash1] == str){
                cout << "yes" << endl;
                return;
            }
        }
        cout << "no" << endl;
}

int main(){
    int n;
    cin >> n;

    int m = findNextPrime(n);
    vector<string> vec_str(m);

    string insfin,str;

    for(int i = 0; i <= (n-1); i++){
        cin >> insfin >> str;
        if(insfin == "insert"){
            insert(str,vec_str,m);
        }else if(insfin == "find"){
            find(str,vec_str,m);
        }
    }

    
    return 0;
}
accuracy: 1
time_ms: 760
memory_kb: 34368
final_rank: 8

code_snippet: #include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#define M 2000003
#define L 14
using namespace std;

char H[M][L];

int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }else if(ch == 'C'){
        return 2;
    }else if(ch == 'G'){
        return 3;
    }else if(ch == 'T'){
        return 4;
    }
    return 0;
}

long long getKey(char str[]){
    long long sum,p;
    sum = 0;
    p = 1;
    for(int i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    int x;
    x = key % M;
    return x;
}
 
int h2(int key){
    int y;
    y = 1 + (key % (M-1));
    return y;
}

int find(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < M; ++i){
        hash = (h_1 + i*h_2) % M;
        if(strcmp(H[hash],str) == 0){
            return 1;
        }
    }
    return 0;
}

int insert(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < M; ++i){
        hash = (h_1 + i*h_2) % M;
        if(H[hash][0] == '\0'){
            strcpy(H[hash],str);
            return 1;
        }
    }
    return 0;
}


int main(){
    int n,h;
    vector<int> result;
    char str[L+1], com[9];
    for(int i = 0; i < M; ++i){
        H[i][0] = '\0';
    }

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> com >> str;
        if(com[0] == 'i'){    
            //入力がinsertなら
            if (!find(str)){
                insert(str);
            }
        }else{
            //入力がfindなら
            if (find(str) == 1){
                result.push_back(1);
            }else{
                result.push_back(0);
            }
        }
    }
    for(int j = 0; j < result.size(); ++j){
        if (result[j] == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}
accuracy: 0.2
time_ms: 1150
memory_kb: 30688
final_rank: 20

code_snippet: #include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#define M 1000003
#define L 14
using namespace std;

char H[M][L];

int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }else if(ch == 'C'){
        return 2;
    }else if(ch == 'G'){
        return 3;
    }else if(ch == 'T'){
        return 4;
    }
    return 0;
}

long long getKey(char str[]){
    long long sum,p;
    sum = 0;
    p = 1;
    for(int i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    int x;
    x = key % M;
    return x;
}
 
int h2(int key){
    int y;
    y = 1 + (key % (M-1));
    return y;
}

int find(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < M; ++i){
        hash = (h_1 + i*h_2) % M;
        if(strcmp(H[hash],str) == 0){
            return 1;
        }
    }
    return 0;
}

int insert(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < M; ++i){
        hash = (h_1 + i*h_2) % M;
        if(H[hash][0] == '\0'){
            strcpy(H[hash],str);
            return 1;
        }
    }
    return 0;
}


int main(){
    int n,h;
    vector<int> result;
    char str[L+1], com[9];
    for(int i = 0; i < M; ++i){
        H[i][0] = '\0';
    }

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> com >> str;
        if(com[0] == 'i'){    
            //入力がinsertなら
            if (!find(str)){
                insert(str);
            }
        }else{
            //入力がfindなら
            if (find(str) == 1){
                result.push_back(1);
            }else{
                result.push_back(0);
            }
        }
    }
    for(int j = 0; j < result.size(); ++j){
        if (result[j] == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}
accuracy: 0.2
time_ms: 490
memory_kb: 17108
final_rank: 19

code_snippet: #include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#define M 1000003
#define L 14
using namespace std;

char H[M][L];

int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }else if(ch == 'C'){
        return 2;
    }else if(ch == 'G'){
        return 3;
    }else if(ch == 'T'){
        return 4;
    }
    return 0;
}

long long getKey(char str[]){
    long long sum,p;
    sum = 0;
    p = 1;
    for(int i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    int x;
    x = key % M;
    return x;
}
 
int h2(int key){
    int y;
    y = 1 + (key % (M-1));
    return y;
}

int find(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < M; ++i){
        hash = (h_1 + i*h_2) % M;
        if(strcmp(H[hash],str) == 0){
            return 1;
        }
    }
    return 0;
}

int insert(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < M; ++i){
        hash = (h_1 + i*h_2) % M;
        if(H[hash][0] == '\0'){
            strcpy(H[hash],str);
            return 1;
        }
    }
    return 0;
}


int main(){
    int n,h;
    vector<int> result;
    char str[L], com[9];
    for(int i = 0; i < M; ++i){
        H[i][0] = '\0';
    }

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> com >> str;
        if(com[0] == 'i'){    
            //入力がinsertなら
            if (!find(str)){
                insert(str);
            }
        }else{
            //入力がfindなら
            if (find(str) == 1){
                result.push_back(1);
            }else{
                result.push_back(0);
            }
        }
    }
    for(int j = 0; j < result.size(); ++j){
        if (result[j] == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}
accuracy: 0.2
time_ms: 480
memory_kb: 17116
final_rank: 17

code_snippet: #include <iostream>
#include <string>
#include <vector>
using namespace std;

long long hs(long long x, int m, int i){
    long long h1 = x % m;
    long long h2 = 1 + x % (m - 1);
    return (h1 + i * h2) % m;
}

long long encode(const string& s){
    long long val = 0;
    for (char c : s){
        val *= 5;
        switch(c){
            case 'A': val += 1; break;
            case 'T': val += 2; break;
            case 'G': val += 3; break;
            case 'C': val += 4; break;
        }
    }
    return val;
}

int main(){
    int n;
    string cmd, s;
    cin >> n;
    vector<long long> H(n, 0);
    vector<string> A;

    for (int i=0; i<n; i++){
        cin >> cmd >> s;
        long long x = encode(s);

        if (cmd == "insert"){
            for (int j=0; j<n; j++){
                long long h = hs(x, n, j);
                if (H[h]==0){
                    H[h] = x;
                    break;
                }
                if (H[h]==x) break; // 既に存在する場合は挿入しない
            }
        }else{ // find
            bool found = false;
            for (int j=0; j<n; j++){
                long long h = hs(x, n, j);
                if (H[h]==0) break; // 空セルに当たったら終了
                if (H[h]==x){
                    A.push_back("yes");
                    found = true;
                    break;
                }
            }
            if (!found) A.push_back("no");
        }
    }

    for (string& ans : A){
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 650
memory_kb: 28736
final_rank: 7

code_snippet: #include <iostream>
#include <string>
#include <vector>
using namespace std;

long long hs(long long x, int m, int i){
    long long h1 = x%m;
    long long h2 = 1+x%(m-1);
    long long h;
    h = (h1 + i * h2) % m;
    return h;
}

int main(){
    int n;
    string cmd, s;
    cin >> n;
    vector<int> H(n);
    vector<string> A;
    for (int i=0;i<n;i++){
        cin >> cmd >> s;
        string s2="";
        for (char i:s){
            switch(i){
                case 'A': s2.push_back('1'); break;
                case 'T': s2.push_back('2'); break;
                case 'G': s2.push_back('3'); break;
                case 'C': s2.push_back('4'); break;
            }
        }
        long long x = stoll(s2);
        int j=0;
        if (cmd == "insert"){
            for(int l=0;l<n;l++){
                long long h = hs(x, n, j);
                if (H[h]==0){
                    H[h] = x;
                    break;
                }
                j+=1;
            }
        }else{
            bool found = false;
            for (int j=0;j<n;j++){
                long long h = hs(x, n, j);
                if (H[h]==0) break;
                if (H[h]==x){
                    //Yes
                    A.push_back("yes");
                    found = true;
                    break;
                }
            }
            if (!found) A.push_back("no");
        }
    }
    for (int k=0;k<A.size();k++){
        cout << A[k] << endl;
    }
}
accuracy: 0.8
time_ms: 710
memory_kb: 24972
final_rank: 13

code_snippet: #include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <cstring> 
#include <unordered_set>

using namespace std;


int main(){
    int n,i,k,f;
    cin >> n;
    string fnc[n];
    string val[n];
    unordered_set<string> dex;
    
    for (i=0;i<n;i++){
        cin >> fnc[i] >> val[i];
    }
    
    
    for (i=0;i<n;i++){
        if (fnc[i]=="insert"){
            dex.insert(val[i]);
        }
        
        
        if (fnc[i]=="find"){
            if (dex.count(val[i])){
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
    
    return 0;
}
accuracy: 1
time_ms: 700
memory_kb: 86260
final_rank: 9

code_snippet: #include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#define M 100003
#define L 100
using namespace std;

char H[M][L];

int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }else if(ch == 'C'){
        return 2;
    }else if(ch == 'G'){
        return 3;
    }else if(ch == 'T'){
        return 4;
    }
    return 0;
}

long long getKey(char str[]){
    long long sum,p;
    sum = 0;
    p = 1;
    for(int i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    int h1;
    h1 = key % M;
    return h1;
}
 
int h2(int key){
    int h2;
    h2 = 1 + (key % (M-1));
    return h2;
}

int find(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(strcmp(H[hash],str) == 0){
            return 1;
        }
    }
    return 0;
}

int insert(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(H[hash][0] == '\0'){
            strcpy(H[hash],str);
            return 1;
        }
    }
    return 0;
}


int main(){
    int n,h;
    vector<int> result;
    char str[L], com[9];
    for(int i = 0; i < M; ++i){
        H[i][0] = '\0';
    }

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> com >> str;
        if(com[0] == 'i'){    
            //入力がinsertなら
            if (!find(str)){
                insert(str);
            }
        }else{
            //入力がfindなら
            if (find(str) == 1){
                result.push_back(1);
            }else{
                result.push_back(0);
            }
        }
    }
    for(int j = 0; j < result.size(); ++j){
        if (result[j] == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}
accuracy: 0.8
time_ms: 970
memory_kb: 14904
final_rank: 14

code_snippet: #include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#define M 78583
#define L 200
using namespace std;

char H[M][L];

int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }else if(ch == 'C'){
        return 2;
    }else if(ch == 'G'){
        return 3;
    }else if(ch == 'T'){
        return 4;
    }
    return 0;
}

long long getKey(char str[]){
    long long sum,p;
    sum = 0;
    p = 1;
    for(int i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    int h1;
    h1 = key % M;
    return h1;
}
 
int h2(int key){
    int h2;
    h2 = 1 + (key % (M-1));
    return h2;
}

int find(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(strcmp(H[hash],str) == 0){
            return 1;
        }
    }
    return 0;
}

int insert(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(H[hash][0] == '\0'){
            strcpy(H[hash],str);
            return 1;
        }
    }
    return 0;
}


int main(){
    int n,h;
    vector<int> result;
    char str[L], com[9];
    for(int i = 0; i < M; ++i){
        H[i][0] = '\0';
    }

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> com >> str;
        if(com[0] == 'i'){    
            //入力がinsertなら
            if (!find(str)){
                insert(str);
            }
        }else{
            //入力がfindなら
            if (find(str) == 1){
                result.push_back(1);
            }else{
                result.push_back(0);
            }
        }
    }
    for(int j = 0; j < result.size(); ++j){
        if (result[j] == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}
accuracy: 0.8
time_ms: 1610
memory_kb: 20304
final_rank: 16

code_snippet: #include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#define M 78583
#define L 100
using namespace std;

char H[M][L];

int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }else if(ch == 'C'){
        return 2;
    }else if(ch == 'G'){
        return 3;
    }else if(ch == 'T'){
        return 4;
    }
    return 0;
}

long long getKey(char str[]){
    long long sum,p;
    sum = 0;
    p = 1;
    for(int i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    int h1;
    h1 = key % M;
    return h1;
}
 
int h2(int key){
    int h2;
    h2 = 1 + (key % (M-1));
    return h2;
}

int find(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(strcmp(H[hash],str) == 0){
            return 1;
        }
    }
    return 0;
}

int insert(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(H[hash][0] == '\0'){
            strcpy(H[hash],str);
            return 1;
        }
    }
    return 0;
}


int main(){
    int n,h;
    vector<int> result;
    char str[L], com[9];
    for(int i = 0; i < M; ++i){
        H[i][0] = '\0';
    }

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> com >> str;
        if(com[0] == 'i'){    
            //入力がinsertなら
            if (!find(str)){
                insert(str);
            }
        }else{
            //入力がfindなら
            if (find(str) == 1){
                result.push_back(1);
            }else{
                result.push_back(0);
            }
        }
    }
    for(int j = 0; j < result.size(); ++j){
        if (result[j] == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}
accuracy: 0.8
time_ms: 1060
memory_kb: 12760
final_rank: 15

code_snippet: #include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#define M 78583
#define L 20
using namespace std;

char H[M][L];

int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }else if(ch == 'C'){
        return 2;
    }else if(ch == 'G'){
        return 3;
    }else if(ch == 'T'){
        return 4;
    }
    return 0;
}

long long getKey(char str[]){
    long long sum,p;
    sum = 0;
    p = 1;
    for(int i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    int h1;
    h1 = key % M;
    return h1;
}
 
int h2(int key){
    int h2;
    h2 = 1 + (key % (M-1));
    return h2;
}

int find(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(strcmp(H[hash],str) == 0){
            return 1;
        }
    }
    return 0;
}

int insert(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(H[hash][0] == '\0'){
            strcpy(H[hash],str);
            return 1;
        }
    }
    return 0;
}


int main(){
    int n,h;
    vector<int> result;
    char str[L], com[9];
    for(int i = 0; i < M; ++i){
        H[i][0] = '\0';
    }

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> com >> str;
        if(com[0] == 'i'){    
            //入力がinsertなら
            if (!find(str)){
                insert(str);
            }
        }else{
            //入力がfindなら
            if (find(str) == 1){
                result.push_back(1);
            }else{
                result.push_back(0);
            }
        }
    }
    for(int j = 0; j < result.size(); ++j){
        if (result[j] == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}
accuracy: 0.8
time_ms: 700
memory_kb: 7696
final_rank: 12

code_snippet: #include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#define M 78583
#define L 14
using namespace std;

char H[M][L];

int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }else if(ch == 'C'){
        return 2;
    }else if(ch == 'G'){
        return 3;
    }else if(ch == 'T'){
        return 4;
    }
    return 0;
}

long long getKey(char str[]){
    long long sum,p;
    sum = 0;
    p = 1;
    for(int i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    int h1;
    h1 = key % M;
    return h1;
}
 
int h2(int key){
    int h2;
    h2 = 1 + (key % (M-1));
    return h2;
}

int find(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(strcmp(H[hash],str) == 0){
            return 1;
        }
    }
    return 0;
}

int insert(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(H[hash][0] == '\0'){
            strcpy(H[hash],str);
            return 1;
        }
    }
    return 0;
}


int main(){
    int n,h;
    vector<int> result;
    char str[L], com[9];
    for(int i = 0; i < M; ++i){
        H[i][0] = '\0';
    }

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> com >> str;
        if(com[0] == 'i'){    
            //入力がinsertなら
            if (!find(str)){
                insert(str);
            }
        }else{
            //入力がfindなら
            if (find(str) == 1){
                result.push_back(1);
            }else{
                result.push_back(0);
            }
        }
    }
    for(int j = 0; j < result.size(); ++j){
        if (result[j] == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}
accuracy: 0.8
time_ms: 670
memory_kb: 6212
final_rank: 10

code_snippet: #include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#define M 76927
#define L 14
using namespace std;

char H[M][L];

int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }else if(ch == 'C'){
        return 2;
    }else if(ch == 'G'){
        return 3;
    }else if(ch == 'T'){
        return 4;
    }
    return 0;
}

long long getKey(char str[]){
    long long sum,p;
    sum = 0;
    p = 1;
    for(int i = 0; i < strlen(str); i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    int h1;
    h1 = key % M;
    return h1;
}
 
int h2(int key){
    int h2;
    h2 = 1 + (key % (M-1));
    return h2;
}

int find(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(strcmp(H[hash],str) == 0){
            return 1;
        }
    }
    return 0;
}

int insert(char str[]){
    int hash,h_1,h_2,key;
    key = getKey(str);
    h_1 = h1(key);
    h_2 = h2(key);
    for(int i = 0;i < L; ++i){
        hash = (h_1 + i*h_2) % M;
        if(H[hash][0] == '\0'){
            strcpy(H[hash],str);
            return 1;
        }
    }
    return 0;
}


int main(){
    int n,h;
    vector<int> result;
    char str[L], com[9];
    for(int i = 0; i < M; ++i){
        H[i][0] = '\0';
    }

    cin >> n;

    for(int i = 0; i < n; ++i){
        cin >> com >> str;
        if(com[0] == 'i'){    
            //入力がinsertなら
            if (!find(str)){
                insert(str);
            }
        }else{
            //入力がfindなら
            if (find(str) == 1){
                result.push_back(1);
            }else{
                result.push_back(0);
            }
        }
    }
    for(int j = 0; j < result.size(); ++j){
        if (result[j] == 1){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
}
accuracy: 0.8
time_ms: 690
memory_kb: 6060
final_rank: 11