problem_id
stringlengths 6
6
| language
stringclasses 2
values | original_status
stringclasses 3
values | original_src
stringlengths 19
243k
| changed_src
stringlengths 19
243k
| change
stringclasses 3
values | i1
int64 0
8.44k
| i2
int64 0
8.44k
| j1
int64 0
8.44k
| j2
int64 0
8.44k
| error
stringclasses 270
values | stderr
stringlengths 0
226k
|
---|---|---|---|---|---|---|---|---|---|---|---|
p02268
|
C++
|
Runtime Error
|
#include <stdio.h>
int BsearchQ(int A[], int n, int key) {
int l = 0;
int r = n;
while (l < r) {
int mid = (l + r) / 2;
if (A[mid] == key) {
return 1;
} else if (A[mid] < key) {
l = mid + 1;
} else {
r = mid;
}
}
return 0;
}
int main() {
int n, A[10000 + 1], q, key, sum = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &A[i]);
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d", &key);
sum += BsearchQ(A, n, key);
}
printf("%d\n", sum);
return 0;
}
|
#include <stdio.h>
int BsearchQ(int A[], int n, int key) {
int l = 0;
int r = n;
while (l < r) {
int mid = (l + r) / 2;
if (A[mid] == key) {
return 1;
} else if (A[mid] < key) {
l = mid + 1;
} else {
r = mid;
}
}
return 0;
}
int main() {
int n, A[100000 + 5], q, key, sum = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &A[i]);
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d", &key);
sum += BsearchQ(A, n, key);
}
printf("%d\n", sum);
return 0;
}
|
replace
| 19 | 20 | 19 | 20 |
0
| |
p02268
|
C++
|
Runtime Error
|
#include <iostream>
int binarySearch(int ary[], int n, int key) {
int left = 0;
int right = n;
int mid = n / 2;
while (left < right) {
if (ary[mid] == key)
return 1;
else if (key < ary[mid])
right = mid;
else
left = mid + 1;
mid = (left + right) / 2;
}
return 0;
}
int main() {
int i, j, key, answer;
int num_of_ary, num_of_key;
int ary[10010];
answer = 0;
std::cin >> num_of_ary;
for (i = 0; i <= num_of_ary - 1; i++)
std::cin >> ary[i];
std::cin >> num_of_key;
for (i = 0; i <= num_of_key - 1; i++) {
std::cin >> key;
answer += binarySearch(ary, num_of_ary, key);
}
std::cout << answer << std::endl;
return 0;
}
|
#include <iostream>
int binarySearch(int ary[], int n, int key) {
int left = 0;
int right = n;
int mid = n / 2;
while (left < right) {
if (ary[mid] == key)
return 1;
else if (key < ary[mid])
right = mid;
else
left = mid + 1;
mid = (left + right) / 2;
}
return 0;
}
int main() {
int i, j, key, answer;
int num_of_ary, num_of_key;
int ary[100010];
answer = 0;
std::cin >> num_of_ary;
for (i = 0; i <= num_of_ary - 1; i++)
std::cin >> ary[i];
std::cin >> num_of_key;
for (i = 0; i <= num_of_key - 1; i++) {
std::cin >> key;
answer += binarySearch(ary, num_of_ary, key);
}
std::cout << answer << std::endl;
return 0;
}
|
replace
| 29 | 30 | 29 | 30 |
0
| |
p02268
|
C++
|
Runtime Error
|
#include <stdio.h>
int Binarysearch(int *, int, int);
#define N 10000
int main() {
int i, s, array[N], t, m, sum = 0;
scanf("%d", &s);
for (i = 0; i < s; i++) {
scanf("%d", &array[i]);
}
scanf("%d", &t);
for (i = 0; i < t; i++) {
scanf("%d", &m);
if (Binarysearch(array, s, m))
sum++;
}
printf("%d\n", sum);
return 0;
}
int Binarysearch(int A[], int x, int key) {
int left = 0, right, mid = 0;
right = x;
while (left < right) {
mid = (left + right) / 2;
if (key == A[mid])
return 1;
else if (key < A[mid])
right = mid;
else if (key > A[mid])
left = mid + 1;
}
return 0;
}
|
#include <stdio.h>
int Binarysearch(int *, int, int);
#define N 100005
int main() {
int i, s, array[N], t, m, sum = 0;
scanf("%d", &s);
for (i = 0; i < s; i++) {
scanf("%d", &array[i]);
}
scanf("%d", &t);
for (i = 0; i < t; i++) {
scanf("%d", &m);
if (Binarysearch(array, s, m))
sum++;
}
printf("%d\n", sum);
return 0;
}
int Binarysearch(int A[], int x, int key) {
int left = 0, right, mid = 0;
right = x;
while (left < right) {
mid = (left + right) / 2;
if (key == A[mid])
return 1;
else if (key < A[mid])
right = mid;
else if (key > A[mid])
left = mid + 1;
}
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p02268
|
C++
|
Runtime Error
|
#include <cassert>
#include <fstream>
#include <iostream>
#include <map>
#include <stack>
#include <string.h>
#include <vector>
// TODO テンプレート化したい
// std::vector<int>::iterator binarySearch(std::vector<int> sorted_array, int
// value)
// {
// int left = 0;
// int right = sorted_array.size();
// while (left < right - 1) {
// int current = (left + right) / 2;
// if(value == sorted_array.at(current)){
// return sorted_array.begin() + current;
// }else if(value < sorted_array.at(current)){
// right = current;
// }else{
// left = current;
// }
// }
// return sorted_array.end();
// }
int binarySearch(std::vector<int> sorted_array, int value) {
int left = 0;
int right = sorted_array.size();
while (left < right) {
int current = (left + right) / 2;
if (value == sorted_array.at(current)) {
return current;
} else if (value < sorted_array.at(current)) {
right = current;
} else {
left = current;
if (current + 1 == right)
break;
}
}
return sorted_array.size();
}
std::vector<int> createVectorFronCin(int cnt) {
std::vector<int> ret;
ret.reserve(cnt);
int cur = 0;
for (int i = 0; i < cnt; ++i) {
std::cin >> cur;
ret.push_back(cur);
}
return ret;
}
int main() {
std::ifstream ifs("input/alds1_04_b_01.txt");
if (!ifs)
assert(false);
std::cin.rdbuf(ifs.rdbuf());
int n = 0;
int q = 0;
std::cin >> n;
std::vector<int> sorted_array = createVectorFronCin(n);
std::cin >> q;
std::vector<int> values = createVectorFronCin(q);
int counter = 0;
for (std::vector<int>::iterator it = values.begin(); it < values.end();
++it) {
int pos = binarySearch(sorted_array, *it);
if (pos < sorted_array.size())
counter++;
// std::vector<int>::iterator pos = binarySearch(sorted_array, *it);
// if (pos != sorted_array.end())
// counter++;
// if (binarySearch(sorted_array, *it) != sorted_array.end())
// counter++;
}
std::cout << counter << std::endl;
}
|
#include <cassert>
#include <fstream>
#include <iostream>
#include <map>
#include <stack>
#include <string.h>
#include <vector>
// TODO テンプレート化したい
// std::vector<int>::iterator binarySearch(std::vector<int> sorted_array, int
// value)
// {
// int left = 0;
// int right = sorted_array.size();
// while (left < right - 1) {
// int current = (left + right) / 2;
// if(value == sorted_array.at(current)){
// return sorted_array.begin() + current;
// }else if(value < sorted_array.at(current)){
// right = current;
// }else{
// left = current;
// }
// }
// return sorted_array.end();
// }
int binarySearch(std::vector<int> sorted_array, int value) {
int left = 0;
int right = sorted_array.size();
while (left < right) {
int current = (left + right) / 2;
if (value == sorted_array.at(current)) {
return current;
} else if (value < sorted_array.at(current)) {
right = current;
} else {
left = current;
if (current + 1 == right)
break;
}
}
return sorted_array.size();
}
std::vector<int> createVectorFronCin(int cnt) {
std::vector<int> ret;
ret.reserve(cnt);
int cur = 0;
for (int i = 0; i < cnt; ++i) {
std::cin >> cur;
ret.push_back(cur);
}
return ret;
}
int main() {
int n = 0;
int q = 0;
std::cin >> n;
std::vector<int> sorted_array = createVectorFronCin(n);
std::cin >> q;
std::vector<int> values = createVectorFronCin(q);
int counter = 0;
for (std::vector<int>::iterator it = values.begin(); it < values.end();
++it) {
int pos = binarySearch(sorted_array, *it);
if (pos < sorted_array.size())
counter++;
// std::vector<int>::iterator pos = binarySearch(sorted_array, *it);
// if (pos != sorted_array.end())
// counter++;
// if (binarySearch(sorted_array, *it) != sorted_array.end())
// counter++;
}
std::cout << counter << std::endl;
}
|
delete
| 63 | 68 | 63 | 63 |
-6
|
1d68f5f0-3617-4774-9b6f-dda702dfac12.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02268/C++/s459023231.cpp:68: int main(): Assertion `false' failed.
|
p02268
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[101];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int t, cnt = 0;
cin >> t;
int q;
for (int i = 0; i < t; i++) {
cin >> q;
if (upper_bound(a, a + n, q) - lower_bound(a, a + n, q)) {
cnt++;
}
}
cout << cnt << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[100001];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int t, cnt = 0;
cin >> t;
int q;
for (int i = 0; i < t; i++) {
cin >> q;
if (upper_bound(a, a + n, q) - lower_bound(a, a + n, q)) {
cnt++;
}
}
cout << cnt << endl;
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <vector>
using namespace std;
bool search(vector<int> &S, int s, int b, int e) {
int m = (e + b) / 2;
int _s = S[m];
if (s == _s)
return true;
if (b == e)
return false;
if (_s > s)
return search(S, s, b, m - 1);
if (_s < s)
return search(S, s, m + 1, e);
}
int main() {
int n;
cin >> n;
vector<int> S(n);
for (auto &s : S)
cin >> s;
int q;
cin >> q;
int C = 0;
while (q--) {
int t;
cin >> t;
if (search(S, t, 0, n - 1))
C++;
}
cout << C << endl;
}
|
#include <iostream>
#include <vector>
using namespace std;
bool search(vector<int> &S, int s, int b, int e) {
int m = (e + b) / 2;
if (m < b)
return false;
int _s = S[m];
if (s == _s)
return true;
if (b == e)
return false;
if (_s > s)
return search(S, s, b, m - 1);
if (_s < s)
return search(S, s, m + 1, e);
}
int main() {
int n;
cin >> n;
vector<int> S(n);
for (auto &s : S)
cin >> s;
int q;
cin >> q;
int C = 0;
while (q--) {
int t;
cin >> t;
if (search(S, t, 0, n - 1))
C++;
}
cout << C << endl;
}
|
insert
| 7 | 7 | 7 | 9 |
TLE
| |
p02268
|
C++
|
Runtime Error
|
#include <stdio.h>
#define N 10000
int S[N], T[N], count = 0, n, q, i, j, minj, temp, left, right, mid;
int binarySearch(int);
int main() {
scanf("%d", &n);
i = 0;
while (i < n) {
scanf("%d", &S[i]);
i++;
}
scanf("%d", &q);
i = 0;
while (i < q) {
scanf("%d", &T[i]);
if (binarySearch(T[i]) == 1) {
count++;
}
i++;
}
printf("%d\n", count);
return 0;
}
int binarySearch(int key) {
left = 0;
right = n;
while (left < right) {
mid = (left + right) / 2;
if (S[mid] == key) {
return 1;
} else if (key < S[mid]) {
right = mid;
} else {
left = mid + 1;
}
}
return 0;
}
|
#include <stdio.h>
#define N 100000
int S[N], T[N], count = 0, n, q, i, j, minj, temp, left, right, mid;
int binarySearch(int);
int main() {
scanf("%d", &n);
i = 0;
while (i < n) {
scanf("%d", &S[i]);
i++;
}
scanf("%d", &q);
i = 0;
while (i < q) {
scanf("%d", &T[i]);
if (binarySearch(T[i]) == 1) {
count++;
}
i++;
}
printf("%d\n", count);
return 0;
}
int binarySearch(int key) {
left = 0;
right = n;
while (left < right) {
mid = (left + right) / 2;
if (S[mid] == key) {
return 1;
} else if (key < S[mid]) {
right = mid;
} else {
left = mid + 1;
}
}
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
void A() {
int S[10000];
int T[500];
int N;
int Q;
int C = 0;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S[i];
}
cin >> Q;
for (int i = 0; i < Q; i++) {
cin >> T[i];
}
for (int i = 0; i < Q; i++) {
for (int j = 0; j < N; j++) {
if (T[i] == S[j]) {
C++;
break;
}
}
}
cout << C << endl;
}
void B() {
int S[100001];
int T[50000];
int N;
int Q;
int C = 0;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S[i];
}
cin >> Q;
for (int i = 0; i < Q; i++) {
cin >> T[i];
}
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
if (S[i] > S[j]) {
int tmp = S[i];
S[i] = S[j];
S[j] = tmp;
}
}
}
for (int i = 0; i < Q; i++) {
int left = 0;
int right = N;
while (left < right) {
int center = (left + right) / 2;
if (T[i] == S[center]) {
C++;
break;
}
if (T[i] > S[center]) {
left = center + 1;
} else {
right = center;
}
}
}
cout << C << endl;
}
int main() {
// A();
B();
return 0;
}
|
#include <iostream>
using namespace std;
void A() {
int S[10000];
int T[500];
int N;
int Q;
int C = 0;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S[i];
}
cin >> Q;
for (int i = 0; i < Q; i++) {
cin >> T[i];
}
for (int i = 0; i < Q; i++) {
for (int j = 0; j < N; j++) {
if (T[i] == S[j]) {
C++;
break;
}
}
}
cout << C << endl;
}
void B() {
int S[100001];
int T[50000];
int N;
int Q;
int C = 0;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> S[i];
}
cin >> Q;
for (int i = 0; i < Q; i++) {
cin >> T[i];
}
for (int i = 0; i < Q; i++) {
int left = 0;
int right = N;
while (left < right) {
int center = (left + right) / 2;
if (T[i] == S[center]) {
C++;
break;
}
if (T[i] > S[center]) {
left = center + 1;
} else {
right = center;
}
}
}
cout << C << endl;
}
int main() {
// A();
B();
return 0;
}
|
delete
| 47 | 57 | 47 | 47 |
TLE
| |
p02268
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int binarySearch(int A[], int n, int key) {
int mid, left = 0, right = n;
while (left < right) {
mid = (left + right) / 2;
if (A[mid] == key)
return 1;
else if (key < A[mid])
right = mid;
else
left = mid + 1;
}
return 0;
}
int main() {
int n, s[10100], q, key, count = 0;
int i, j, k;
cin >> n;
for (i = 0; i < n; i++)
scanf("%d", &s[i]);
cin >> q;
for (i = 0; i < q; i++) {
scanf("%d", &key);
if (binarySearch(s, n, key))
count++;
}
cout << count << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int binarySearch(int A[], int n, int key) {
int mid, left = 0, right = n;
while (left < right) {
mid = (left + right) / 2;
if (A[mid] == key)
return 1;
else if (key < A[mid])
right = mid;
else
left = mid + 1;
}
return 0;
}
int main() {
int n, s[100100], q, key, count = 0;
int i, j, k;
cin >> n;
for (i = 0; i < n; i++)
scanf("%d", &s[i]);
cin >> q;
for (i = 0; i < q; i++) {
scanf("%d", &key);
if (binarySearch(s, n, key))
count++;
}
cout << count << endl;
return 0;
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p02268
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
bool myBinarySearch(int S[], int begin, int end, int target) {
if (begin > end) {
return false;
}
int mid = (begin + end) / 2;
if (S[mid] > target) {
return myBinarySearch(S, begin, mid - 1, target);
} else if (S[mid] < target) {
return myBinarySearch(S, mid + 1, end, target);
} else {
return true;
}
}
int main(void) {
int S[10000];
int T[500];
int n, m;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> S[i];
}
sort(S, S + m);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> T[i];
}
sort(T, T + n);
int ans = 0;
for (int i = 0; i < n; i++) {
if (myBinarySearch(S, 0, m, T[i])) {
ans++;
}
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
bool myBinarySearch(int S[], int begin, int end, int target) {
if (begin > end) {
return false;
}
int mid = (begin + end) / 2;
if (S[mid] > target) {
return myBinarySearch(S, begin, mid - 1, target);
} else if (S[mid] < target) {
return myBinarySearch(S, mid + 1, end, target);
} else {
return true;
}
}
int main(void) {
int S[100000];
int T[50000];
int n, m;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> S[i];
}
sort(S, S + m);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> T[i];
}
sort(T, T + n);
int ans = 0;
for (int i = 0; i < n; i++) {
if (myBinarySearch(S, 0, m, T[i])) {
ans++;
}
}
cout << ans << endl;
return 0;
}
|
replace
| 20 | 22 | 20 | 22 |
0
| |
p02268
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int s[10003], t[5003];
int n, q;
cin >> n;
REP(i, n) cin >> s[i];
cin >> q;
REP(i, q) cin >> t[i];
int ct = 0;
REP(i, q) {
int l = 0;
int r = n;
while (abs(r - l) > 1) {
int mid = (r + l) / 2;
if (t[i] < s[mid])
r = mid;
else
l = mid;
}
if (s[(r + l) / 2] == t[i])
ct++;
}
cout << ct << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int s[100003], t[50003];
int n, q;
cin >> n;
REP(i, n) cin >> s[i];
cin >> q;
REP(i, q) cin >> t[i];
int ct = 0;
REP(i, q) {
int l = 0;
int r = n;
while (abs(r - l) > 1) {
int mid = (r + l) / 2;
if (t[i] < s[mid])
r = mid;
else
l = mid;
}
if (s[(r + l) / 2] == t[i])
ct++;
}
cout << ct << endl;
return 0;
}
|
replace
| 29 | 30 | 29 | 30 |
0
| |
p02268
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
int binarySearch(int n, int s[], int t) {
int i = 0;
int j = n - 1;
while (i <= j) {
int mid = i + (j - i) / 2;
int guess = s[mid];
if (guess == t) {
return 1;
}
if (guess < t) {
i = mid + 1;
} else {
j = mid - 1;
}
}
return 0;
}
int main() {
int n, q, s[10001], t, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
cin >> q;
for (int i = 0; i < q; i++) {
cin >> t;
ans += binarySearch(n, s, t);
}
cout << ans << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int binarySearch(int n, int s[], int t) {
int i = 0;
int j = n - 1;
while (i <= j) {
int mid = i + (j - i) / 2;
int guess = s[mid];
if (guess == t) {
return 1;
}
if (guess < t) {
i = mid + 1;
} else {
j = mid - 1;
}
}
return 0;
}
int main() {
int n, q, s[100000], t, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
cin >> q;
for (int i = 0; i < q; i++) {
cin >> t;
ans += binarySearch(n, s, t);
}
cout << ans << endl;
return 0;
}
|
replace
| 22 | 23 | 22 | 23 |
0
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> lake;
int main(void) {
int n, q;
cin >> n;
vector<int> s(n);
for (int i = 0; i < n; i++)
cin >> s[i];
cin >> q;
vector<int> t(q);
for (int i = 0; i < q; i++)
cin >> t[i];
// sort(s.begin(), s.end());
// sort(t.begin(), t.end());
int count = 0;
for (int i = 0; i < q; i++) {
int left = 0;
int right = n;
while (left < right) {
int mid = (left + right) / 2;
if (s[mid] == t[i]) {
count++;
break;
} else if (s[mid] < t[i]) {
left = mid;
} else {
right = mid;
}
}
}
cout << count << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> lake;
int main(void) {
int n, q;
cin >> n;
vector<int> s(n);
for (int i = 0; i < n; i++)
cin >> s[i];
cin >> q;
vector<int> t(q);
for (int i = 0; i < q; i++)
cin >> t[i];
// sort(s.begin(), s.end());
// sort(t.begin(), t.end());
int count = 0;
for (int i = 0; i < q; i++) {
int left = 0;
int right = n;
while (left < right) {
int mid = (left + right) / 2;
if (s[mid] == t[i]) {
count++;
break;
} else if (s[mid] < t[i]) {
left = mid + 1;
} else {
right = mid;
}
}
}
cout << count << endl;
return 0;
}
|
replace
| 36 | 37 | 36 | 37 |
TLE
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
int main() {
int n, q;
cin >> n;
int S[n];
for (int k = 0; k < n; k++) {
cin >> S[k];
}
cin >> q;
int T[q];
for (int l = 0; l < q; l++) {
cin >> T[l];
}
int count = 0;
for (int j = 0; j < q; j++) {
int left = 0;
int right = n;
while (left < right) {
int mid = (left + right) / 2;
if (S[mid] == T[j]) {
count += 1;
} else if (T[j] < S[mid]) {
right = mid;
} else {
left = mid + 1;
}
}
}
cout << count << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n, q;
cin >> n;
int S[n];
for (int k = 0; k < n; k++) {
cin >> S[k];
}
cin >> q;
int T[q];
for (int l = 0; l < q; l++) {
cin >> T[l];
}
int count = 0;
for (int j = 0; j < q; j++) {
int left = 0;
int right = n;
while (left < right) {
int mid = (left + right) / 2;
if (S[mid] == T[j]) {
count += 1;
break;
} else if (T[j] < S[mid]) {
right = mid;
} else {
left = mid + 1;
}
}
}
cout << count << endl;
return 0;
}
|
insert
| 25 | 25 | 25 | 26 |
TLE
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
using namespace std;
bool binary_search(vector<int> v, int kay, bool is_sorted) {
if (is_sorted)
sort(ALL(v));
int left = 0;
int right = SZ(v);
int mid;
while (left < right) {
mid = (left + right) / 2;
if (v[mid] == kay)
return true;
else if (kay < v[mid])
right = mid;
else
left = mid + 1;
}
return false;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> v;
int t;
REP(_, n) {
cin >> t;
v.PB(t);
}
cin >> n;
int count = 0;
REP(_, n) {
cin >> t;
if (binary_search(v, t, true))
count++;
}
cout << count << endl;
}
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
using namespace std;
bool binary_search(vector<int> v, int kay, bool is_sorted) {
if (!is_sorted)
sort(ALL(v));
int left = 0;
int right = SZ(v);
int mid;
while (left < right) {
mid = (left + right) / 2;
if (v[mid] == kay)
return true;
else if (kay < v[mid])
right = mid;
else
left = mid + 1;
}
return false;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> v;
int t;
REP(_, n) {
cin >> t;
v.PB(t);
}
cin >> n;
int count = 0;
REP(_, n) {
cin >> t;
if (binary_search(v, t, true))
count++;
}
cout << count << endl;
}
|
replace
| 20 | 21 | 20 | 21 |
TLE
| |
p02268
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q, S[10000], T, res = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> S[i];
}
sort(S, S + n);
cin >> q;
for (int i = 0; i < q; i++) {
cin >> T;
if (binary_search(S, S + n, T))
res++;
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q, S[100000], T, res = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> S[i];
}
sort(S, S + n);
cin >> q;
for (int i = 0; i < q; i++) {
cin >> T;
if (binary_search(S, S + n, T))
res++;
}
cout << res << endl;
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <cstdio>
using namespace std;
int A[100000];
int search(int key, int n) {
int left = 0;
int right = n;
int mid;
while (left < right) { //??????????????£?????????notfound
mid = (left + right) / 2;
if (A[mid] == key)
return 1;
else if (key < A[mid]) { // motto left
right = mid;
} else {
left = mid;
}
}
return 0;
}
int main() {
int n, q, key;
int cnt = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &A[i]);
}
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d", &key);
if (search(key, n))
cnt++;
}
printf("%d\n", cnt);
return 0;
}
|
#include <cstdio>
using namespace std;
int A[100000];
int search(int key, int n) {
int left = 0;
int right = n;
int mid;
while (left < right) { //??????????????£?????????notfound
mid = (left + right) / 2;
if (A[mid] == key)
return 1;
else if (key < A[mid]) { // motto left
right = mid;
} else {
left = mid + 1; //?????¶???????????????????
}
}
return 0;
}
int main() {
int n, q, key;
int cnt = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &A[i]);
}
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d", &key);
if (search(key, n))
cnt++;
}
printf("%d\n", cnt);
return 0;
}
|
replace
| 16 | 17 | 16 | 17 |
TLE
| |
p02268
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
bool binarySearch(int a[], int n, int x) {
int mid;
int left = 0;
int right = n;
while (left < right) {
mid = (left + right) / 2;
if (a[mid] == x)
return true;
else if (x < a[mid])
right = mid;
else
left = mid + 1;
}
return false;
}
int main(void) {
int n, q, sum = 0;
int S[10001], T[10001];
/* input */
std::cin >> n;
for (int i = 0; i < n; i++) {
std::cin >> S[i];
}
std::cin >> q;
for (int i = 0; i < q; i++) {
std::cin >> T[i];
}
for (int i = 0; i < q; i++) {
if (binarySearch(S, n, T[i])) {
sum++;
}
}
cout << sum << "\n";
return 0;
}
|
#include <iostream>
using namespace std;
bool binarySearch(int a[], int n, int x) {
int mid;
int left = 0;
int right = n;
while (left < right) {
mid = (left + right) / 2;
if (a[mid] == x)
return true;
else if (x < a[mid])
right = mid;
else
left = mid + 1;
}
return false;
}
int main(void) {
int n, q, sum = 0;
int S[100001], T[50001];
/* input */
std::cin >> n;
for (int i = 0; i < n; i++) {
std::cin >> S[i];
}
std::cin >> q;
for (int i = 0; i < q; i++) {
std::cin >> T[i];
}
for (int i = 0; i < q; i++) {
if (binarySearch(S, n, T[i])) {
sum++;
}
}
cout << sum << "\n";
return 0;
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <map>
#include <set>
#include <vector>
int main(void) {
int ans = 0;
int n, q;
std::cin >> n;
std::vector<int> arr(n);
for (auto &a : arr)
std::cin >> a;
std::cin >> q;
for (size_t i = 0; i < q; i++) {
int in = 0;
std::cin >> in;
int left = 0, mid = n / 2, right = n;
while (left != right) {
if (arr[mid] == in) {
ans++;
break;
}
if (in < arr[mid])
right = mid;
else
left = mid;
mid = (right + left) / 2;
}
}
std::cout << ans << std::endl;
return 0;
}
|
#include <iostream>
#include <map>
#include <set>
#include <vector>
int main(void) {
int ans = 0;
int n, q;
std::cin >> n;
std::vector<int> arr(n);
for (auto &a : arr)
std::cin >> a;
std::cin >> q;
for (size_t i = 0; i < q; i++) {
int in = 0;
std::cin >> in;
int left = 0, mid = n / 2, right = n;
while (left != right) {
if (arr[mid] == in) {
ans++;
break;
}
if (in < arr[mid])
right = mid;
else
left = mid + 1;
mid = (right + left) / 2;
}
}
std::cout << ans << std::endl;
return 0;
}
|
replace
| 25 | 26 | 25 | 26 |
TLE
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <stdio.h>
int A[1000000], n;
int binarySearch(int key) {
int left = 0;
int right = n;
int mid;
while (left < right) {
mid = (left + right) / 2;
if (key == A[mid])
return 1;
if (key > A[mid])
left = mid + 1;
else if (key < A[mid])
right = mid;
}
return 0;
}
int main(void) {
int i, q, k, sum = 0;
scanf("%d", &n);
for (i = 0; k < n; i++) {
scanf("%d", &A[i]);
}
scanf("%d", &q);
for (i = 0; i < q; i++) {
scanf("%d", &k);
if (binarySearch(k))
sum++;
}
printf("%d\n", sum);
return 0;
}
|
#include <stdio.h>
int A[1000000], n;
int binarySearch(int key) {
int left = 0;
int right = n;
int mid;
while (left < right) {
mid = (left + right) / 2;
if (key == A[mid])
return 1;
if (key > A[mid])
left = mid + 1;
else if (key < A[mid])
right = mid;
}
return 0;
}
int main(void) {
int i, q, k, sum = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &A[i]);
}
scanf("%d", &q);
for (i = 0; i < q; i++) {
scanf("%d", &k);
if (binarySearch(k))
sum++;
}
printf("%d\n", sum);
return 0;
}
|
replace
| 25 | 26 | 25 | 26 |
TLE
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, n) for (int i = (a); i > n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
inline int f(int n, vi s, int q, vi t) {
int cnt = 0;
rep(j, 0, q) {
if (count(all(s), t[j]))
++cnt;
}
return cnt;
}
int main() {
int n;
cin >> n;
unordered_set<int> ss;
{
ll t;
rep(i, 0, n) {
cin >> t;
ss.emplace(t);
}
}
vi s(all(ss));
int q;
cin >> q;
vi t(q);
rep(i, 0, q) cin >> t[i];
P(f(len(s), s, q, t));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i, a, n) for (int i = (a), i##_len = (n); i < i##_len; ++i)
#define rrep(i, a, n) for (int i = (a); i > n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
inline int f(int n, vi s, int q, vi t) {
int cnt = 0;
rep(j, 0, q) {
if (find(all(s), t[j]) != s.end())
++cnt;
}
return cnt;
}
int main() {
int n;
cin >> n;
unordered_set<int> ss;
{
ll t;
rep(i, 0, n) {
cin >> t;
ss.emplace(t);
}
}
vi s(all(ss));
int q;
cin >> q;
vi t(q);
rep(i, 0, q) cin >> t[i];
P(f(len(s), s, q, t));
return 0;
}
|
replace
| 27 | 28 | 27 | 28 |
TLE
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
int main() {
int S[100000], T[100000], n, q, key, low = 0, upper = 0, mid, flag;
int i = 0, cnt = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> S[i];
}
cin >> q;
for (int i = 0; i < q; i++) {
cin >> T[i];
}
for (i = 0; i < q; i++) {
///------------------------------
key = T[i];
low = 0;
upper = 0;
mid = 0;
upper = n; // n-1
mid = (low + upper) / 2;
while (low <= upper) {
// mid=(low+upper)/2;
if (S[mid] == key) {
flag = 1;
cnt++;
break;
}
if (S[mid] < key) {
low = mid + 1;
} else {
upper = mid; // mid-1
}
mid = (low + upper) / 2; //
}
if (flag != 1) {
// no
}
///------------------------------
}
cout << cnt << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int S[100000], T[100000], n, q, key, low = 0, upper = 0, mid, flag;
int i = 0, cnt = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> S[i];
}
cin >> q;
for (int i = 0; i < q; i++) {
cin >> T[i];
}
for (i = 0; i < q; i++) {
///------------------------------
key = T[i];
low = 0;
upper = 0;
mid = 0;
upper = n; // n-1
mid = (low + upper) / 2;
while (low < upper) {
// mid=(low+upper)/2;
if (S[mid] == key) {
flag = 1;
cnt++;
break;
}
if (S[mid] < key) {
low = mid + 1;
} else {
upper = mid; // mid-1
}
mid = (low + upper) / 2; //
}
if (flag != 1) {
// no
}
///------------------------------
}
cout << cnt << endl;
return 0;
}
|
replace
| 26 | 27 | 26 | 27 |
TLE
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <iostream>
int binarySearch(int s[], int n, int key) {
int head = 0;
int tail = n - 1;
int center;
while (head != tail) {
center = (head + tail) / 2;
if (s[center] == key) {
return center;
} else if (s[center] < key) {
head = center + 1;
} else {
tail = center - 1;
}
}
if (s[head] == key) {
return head;
}
return -1;
}
int main() {
int n, q;
int cnt = 0;
std::cin >> n;
int s[n];
for (int i = 0; i < n; i++) {
std::cin >> s[i];
}
std::cin >> q;
int key;
for (int i = 0; i < q; i++) {
std::cin >> key;
if (binarySearch(s, n, key) >= 0) {
cnt++;
}
}
std::cout << cnt << "\n";
}
|
#include <iostream>
int binarySearch(int s[], int n, int key) {
int head = 0;
int tail = n - 1;
int center;
while (head != tail) {
center = (head + tail) / 2;
if (s[center] == key) {
return center;
} else if (s[center] < key) {
head = center + 1;
} else {
tail = center;
}
}
if (s[head] == key) {
return head;
}
return -1;
}
int main() {
int n, q;
int cnt = 0;
std::cin >> n;
int s[n];
for (int i = 0; i < n; i++) {
std::cin >> s[i];
}
std::cin >> q;
int key;
for (int i = 0; i < q; i++) {
std::cin >> key;
if (binarySearch(s, n, key) >= 0) {
cnt++;
}
}
std::cout << cnt << "\n";
}
|
replace
| 16 | 17 | 16 | 17 |
TLE
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#define MAXN 200000 + 10
using namespace std;
int s[MAXN];
int t[MAXN];
int ns, nt;
int tot, l, r, mid;
int main() {
int i, now;
cin >> ns;
for (i = 0; i < ns; ++i)
cin >> s[i];
cin >> nt;
for (i = 0; i < nt; ++i)
cin >> t[i];
for (i = 0; i < nt; ++i) {
now = t[i];
l = 0;
r = ns;
while (l < r) {
mid = l + (r - l) / 2;
if (s[mid] == now) {
tot++;
break;
}
if (s[mid] < now)
l = mid;
else
r = mid;
}
}
cout << tot << endl;
return 0;
}
|
#include <iostream>
#define MAXN 200000 + 10
using namespace std;
int s[MAXN];
int t[MAXN];
int ns, nt;
int tot, l, r, mid;
int main() {
int i, now;
cin >> ns;
for (i = 0; i < ns; ++i)
cin >> s[i];
cin >> nt;
for (i = 0; i < nt; ++i)
cin >> t[i];
for (i = 0; i < nt; ++i) {
now = t[i];
l = 0;
r = ns;
while (l < r) {
mid = l + (r - l) / 2;
if (s[mid] == now) {
tot++;
break;
}
if (s[mid] < now)
l = mid + 1;
else
r = mid;
}
}
cout << tot << endl;
return 0;
}
|
replace
| 27 | 28 | 27 | 28 |
TLE
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#define MAXN 100000
#define MAXQ 50000
using namespace std;
int n, q;
int S[MAXN + 1], T[MAXQ + 1];
int cnt = 0;
bool binarySearch(int num) {
int lo, mi, hi;
bool res = false;
lo = 0;
mi = hi = n;
while (1 < mi) {
mi = (lo + hi) / 2;
if (num < S[mi]) {
hi = mi - 1;
} else if (S[mi] < num) {
lo = mi + 1;
} else {
res = true;
break;
}
}
return res;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> S[i];
}
cin >> q;
for (int i = 0; i < q; i++) {
cin >> T[i];
cnt += binarySearch(T[i]);
}
cout << cnt << endl;
return 0;
}
|
#include <iostream>
#define MAXN 100000
#define MAXQ 50000
using namespace std;
int n, q;
int S[MAXN + 1], T[MAXQ + 1];
int cnt = 0;
bool binarySearch(int num) {
int lo, mi, hi;
bool res = false;
lo = 0;
mi = hi = n;
while (lo <= hi) {
mi = (lo + hi) / 2;
if (num < S[mi]) {
hi = mi - 1;
} else if (S[mi] < num) {
lo = mi + 1;
} else {
res = true;
break;
}
}
return res;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> S[i];
}
cin >> q;
for (int i = 0; i < q; i++) {
cin >> T[i];
cnt += binarySearch(T[i]);
}
cout << cnt << endl;
return 0;
}
|
replace
| 16 | 17 | 16 | 17 |
TLE
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 8;
int n, q, x, num;
int s[maxn];
bool is_find(int x) {
int left, right, mid;
left = 0;
right = n;
while (left <= right) {
mid = (left + right) / 2;
if (s[mid] == x)
return true;
else if (s[mid] > x) {
right = mid;
} else if (s[mid] < x) {
left = mid + 1;
}
}
return false;
}
int main() {
scanf("%d", &n);
num = 0;
for (int i = 0; i < n; ++i)
scanf("%d", &s[i]);
sort(s, s + n);
scanf("%d", &q);
for (int i = 0; i < q; ++i) {
scanf("%d", &x);
if (is_find(x))
num++;
}
printf("%d\n", num);
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 8;
int n, q, x, num;
int s[maxn];
bool is_find(int x) {
int left, right, mid;
left = 0;
right = n;
while (left < right) {
mid = (left + right) / 2;
if (s[mid] == x)
return true;
else if (s[mid] > x) {
right = mid;
} else if (s[mid] < x) {
left = mid + 1;
}
}
return false;
}
int main() {
scanf("%d", &n);
num = 0;
for (int i = 0; i < n; ++i)
scanf("%d", &s[i]);
sort(s, s + n);
scanf("%d", &q);
for (int i = 0; i < q; ++i) {
scanf("%d", &x);
if (is_find(x))
num++;
}
printf("%d\n", num);
return 0;
}
|
replace
| 23 | 24 | 23 | 24 |
TLE
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <vector>
using namespace std;
bool find(const vector<int> &S, int begin, int end, int x) {
if (end - begin <= 0) {
return false;
}
int mid = (begin + end) / 2;
if (x < S[mid]) {
return find(S, begin, mid, x);
} else if (S[mid] < x) {
return find(S, mid, end, x);
} else {
return true;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> S(n);
for (int i = 0; i < n; ++i) {
cin >> S[i];
}
int q;
cin >> q;
vector<int> T(q);
for (int i = 0; i < q; ++i) {
cin >> T[i];
}
int count = 0;
for (int i = 0; i < q; ++i) {
if (find(S, 0, S.size(), T[i])) {
++count;
}
}
cout << count << endl;
}
|
#include <iostream>
#include <vector>
using namespace std;
bool find(const vector<int> &S, int begin, int end, int x) {
if (end - begin == 1) {
return S[begin] == x;
}
int mid = (begin + end) / 2;
if (x < S[mid]) {
return find(S, begin, mid, x);
} else if (S[mid] < x) {
return find(S, mid, end, x);
} else {
return true;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> S(n);
for (int i = 0; i < n; ++i) {
cin >> S[i];
}
int q;
cin >> q;
vector<int> T(q);
for (int i = 0; i < q; ++i) {
cin >> T[i];
}
int count = 0;
for (int i = 0; i < q; ++i) {
if (find(S, 0, S.size(), T[i])) {
++count;
}
}
cout << count << endl;
}
|
replace
| 6 | 8 | 6 | 8 |
TLE
| |
p02268
|
C++
|
Runtime Error
|
#include <stdio.h>
int binarySearch(int A[], int n, int key) {
int left = 0;
int right = n;
while (left < right) {
int mid = (left + right) / 2;
if (A[mid] == key)
return 1;
else if (A[mid] < key)
left = mid + 1;
else
right = mid;
}
return 0;
}
int main() {
int i, n, A[10000 + 1], q, key, sum = 0;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &A[i]);
scanf("%d", &q);
for (i = 0; i < q; i++) {
scanf("%d", &key);
if (binarySearch(A, n, key))
sum++;
}
printf("%d\n", sum);
return 0;
}
|
#include <stdio.h>
int binarySearch(int A[], int n, int key) {
int left = 0;
int right = n;
while (left < right) {
int mid = (left + right) / 2;
if (A[mid] == key)
return 1;
else if (A[mid] < key)
left = mid + 1;
else
right = mid;
}
return 0;
}
int main() {
int i, n, A[100000 + 1], q, key, sum = 0;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &A[i]);
scanf("%d", &q);
for (i = 0; i < q; i++) {
scanf("%d", &key);
if (binarySearch(A, n, key))
sum++;
}
printf("%d\n", sum);
return 0;
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p02268
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;
#include <map>
#include <queue>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N = 1000000;
int NS;
int S[MAX_N];
int NT;
int T[MAX_N];
// not the most left
int binarySearch(int A[], int N, int key) {
int left = 0;
int right = N;
while (left < right) {
int mid = (left + right) / 2;
if (A[mid] == key) {
return mid;
} else if (key < A[mid]) {
right = mid;
} else {
left = mid;
}
}
return -1;
}
int main() {
cin >> NS;
rep(i, NS) { cin >> S[i]; }
cin >> NT;
rep(i, NT) { cin >> T[i]; }
int ret = 0;
rep(i, NT) {
if (binarySearch(S, NS, T[i]) >= 0)
ret++;
}
cout << ret << endl;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;
#include <map>
#include <queue>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N = 1000000;
int NS;
int S[MAX_N];
int NT;
int T[MAX_N];
// not the most left
int binarySearch(int A[], int N, int key) {
int left = 0;
int right = N;
while (left < right) {
int mid = (left + right) / 2;
if (A[mid] == key) {
return mid;
} else if (key < A[mid]) {
right = mid;
} else {
left = mid + 1;
}
}
return -1;
}
int main() {
cin >> NS;
rep(i, NS) { cin >> S[i]; }
cin >> NT;
rep(i, NT) { cin >> T[i]; }
int ret = 0;
rep(i, NT) {
if (binarySearch(S, NS, T[i]) >= 0)
ret++;
}
cout << ret << endl;
}
|
replace
| 39 | 40 | 39 | 40 |
TLE
| |
p02268
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
template <const int U = 1 << 30> class vEB {
struct node {
int min, max;
node *summary, **cluster;
node() : min(U), max(-1), summary(nullptr), cluster(nullptr) {}
} *root;
int cnt;
private:
int downsqrt(int ub) const { return ub >> 1; }
int upsqrt(int ub) { return (ub >> 1) + (ub & 1); }
int high(int x, int ub) const { return x >> ub; }
int low(int x, int ub) const { return x & ((1 << ub) - 1); }
int index(int x, int y, int ub) const { return (x << downsqrt(ub)) + y; }
int minimum(node *v) const { return v ? v->min : U; }
int maximum(node *v) const { return v ? v->max : -1; }
bool member(node *v, int x, int ub) const {
if (!v)
return false;
if (v->min == x || v->max == x)
return true;
if (!v->cluster)
return false;
return member(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub));
}
node *new_node(int ub) {
node *v = new node();
if (ub > 1) {
int sz = 1 << upsqrt(ub);
v->cluster = new node *[sz];
for (int i = 0; i < sz; i++) {
v->cluster[i] = nullptr;
}
}
return v;
}
node *empty_insert(node *v, int x, int ub) {
if (!v)
v = new_node(ub);
v->min = v->max = x;
return v;
}
node *insert(node *v, int x, int ub) {
if (!v)
v = new_node(ub);
if (v->min == U) {
empty_insert(v, x, ub);
return v;
}
if (x < v->min)
swap(x, v->min);
if (ub > 1) {
if (minimum(v->cluster[high(x, ub)]) == U) {
v->summary = insert(v->summary, high(x, ub), upsqrt(ub));
v->cluster[high(x, ub)] =
empty_insert(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub));
} else {
v->cluster[high(x, ub)] =
insert(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub));
}
}
if (x > v->max)
v->max = x;
return v;
}
node *erase(node *v, int x, int ub) {
if (v->min == v->max) {
v->min = U;
v->max = -1;
return nullptr;
}
if (ub <= 1) {
v->max = v->min = (x == 0);
return v;
}
if (x == v->min) {
int first_cluster = minimum(v->summary);
v->min = x = index(first_cluster, minimum(v->cluster[first_cluster]), ub);
}
v->cluster[high(x, ub)] =
erase(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub));
if (minimum(v->cluster[high(x, ub)]) == U) {
v->summary = erase(v->summary, high(x, ub), upsqrt(ub));
if (x == v->max) {
int summary_max = maximum(v->summary);
if (summary_max == -1) {
v->max = v->min;
} else {
v->max = index(summary_max, maximum(v->cluster[summary_max]), ub);
}
}
} else if (x == v->max) {
v->max = index(high(x, ub), maximum(v->cluster[high(x, ub)]), ub);
}
return v;
}
int successor(node *v, int x, int ub) const {
if (ub <= 1) {
if (x == 0 && v->max == 1)
return 1;
return U;
}
if (v->min != U && x < v->min)
return v->min;
int max_low = maximum(v->cluster[high(x, ub)]);
if (max_low != -1 && low(x, ub) < max_low) {
return index(high(x, ub),
successor(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub)),
ub);
}
int succ_cluster = successor(v->summary, high(x, ub), upsqrt(ub));
if (succ_cluster == U)
return U;
return index(succ_cluster, minimum(v->cluster[succ_cluster]), ub);
}
int predecessor(node *v, int x, int ub) const {
if (ub <= 1) {
if (x == 1 && v->min == 0)
return 0;
return -1;
}
if (v->max != -1 && x > v->max)
return v->max;
int min_low = minimum(v->cluster[high(x, ub)]);
if (min_low != U && low(x, ub) > min_low) {
return index(
high(x, ub),
predecessor(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub)), ub);
}
int pred_cluster = predecessor(v->summary, high(x, ub), upsqrt(ub));
if (pred_cluster == -1) {
if (v->min != -1 && x > v->min)
return v->min;
return -1;
}
return index(pred_cluster, maximum(v->cluster[pred_cluster]), ub);
}
public:
vEB() : root(nullptr), cnt(0) {}
int size() const { return cnt; }
bool member(int x) const { return member(root, x, __builtin_ctz(U)); }
int minimum() const { return minimum(root); }
int maximum() const { return maximum(root); }
void insert(int x) {
if (!member(x))
root = insert(root, x, __builtin_ctz(U)), cnt++;
}
void erase(int x) {
if (member(x))
root = erase(root, x, __builtin_ctz(U)), cnt--;
}
int successor(int x) const { return successor(root, x, __builtin_ctz(U)); }
int predecessor(int x) const {
return predecessor(root, x, __builtin_ctz(U));
}
};
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, q;
cin >> n;
vEB<> veb;
for (int i = 0; i < n; i++) {
int si;
cin >> si;
veb.insert(si);
}
int res = 0;
cin >> q;
for (int j = 0; j < q; j++) {
int ti;
cin >> ti;
res += veb.member(ti);
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <const int U = 1 << 30> class vEB {
struct node {
int min, max;
node *summary, **cluster;
node() : min(U), max(-1), summary(nullptr), cluster(nullptr) {}
} *root;
int cnt;
private:
int downsqrt(int ub) const { return ub >> 1; }
int upsqrt(int ub) { return (ub >> 1) + (ub & 1); }
int high(int x, int ub) const { return x >> downsqrt(ub); }
int low(int x, int ub) const { return x & ((1 << downsqrt(ub)) - 1); }
int index(int x, int y, int ub) const { return (x << downsqrt(ub)) + y; }
int minimum(node *v) const { return v ? v->min : U; }
int maximum(node *v) const { return v ? v->max : -1; }
bool member(node *v, int x, int ub) const {
if (!v)
return false;
if (v->min == x || v->max == x)
return true;
if (!v->cluster)
return false;
return member(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub));
}
node *new_node(int ub) {
node *v = new node();
if (ub > 1) {
int sz = 1 << upsqrt(ub);
v->cluster = new node *[sz];
for (int i = 0; i < sz; i++) {
v->cluster[i] = nullptr;
}
}
return v;
}
node *empty_insert(node *v, int x, int ub) {
if (!v)
v = new_node(ub);
v->min = v->max = x;
return v;
}
node *insert(node *v, int x, int ub) {
if (!v)
v = new_node(ub);
if (v->min == U) {
empty_insert(v, x, ub);
return v;
}
if (x < v->min)
swap(x, v->min);
if (ub > 1) {
if (minimum(v->cluster[high(x, ub)]) == U) {
v->summary = insert(v->summary, high(x, ub), upsqrt(ub));
v->cluster[high(x, ub)] =
empty_insert(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub));
} else {
v->cluster[high(x, ub)] =
insert(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub));
}
}
if (x > v->max)
v->max = x;
return v;
}
node *erase(node *v, int x, int ub) {
if (v->min == v->max) {
v->min = U;
v->max = -1;
return nullptr;
}
if (ub <= 1) {
v->max = v->min = (x == 0);
return v;
}
if (x == v->min) {
int first_cluster = minimum(v->summary);
v->min = x = index(first_cluster, minimum(v->cluster[first_cluster]), ub);
}
v->cluster[high(x, ub)] =
erase(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub));
if (minimum(v->cluster[high(x, ub)]) == U) {
v->summary = erase(v->summary, high(x, ub), upsqrt(ub));
if (x == v->max) {
int summary_max = maximum(v->summary);
if (summary_max == -1) {
v->max = v->min;
} else {
v->max = index(summary_max, maximum(v->cluster[summary_max]), ub);
}
}
} else if (x == v->max) {
v->max = index(high(x, ub), maximum(v->cluster[high(x, ub)]), ub);
}
return v;
}
int successor(node *v, int x, int ub) const {
if (ub <= 1) {
if (x == 0 && v->max == 1)
return 1;
return U;
}
if (v->min != U && x < v->min)
return v->min;
int max_low = maximum(v->cluster[high(x, ub)]);
if (max_low != -1 && low(x, ub) < max_low) {
return index(high(x, ub),
successor(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub)),
ub);
}
int succ_cluster = successor(v->summary, high(x, ub), upsqrt(ub));
if (succ_cluster == U)
return U;
return index(succ_cluster, minimum(v->cluster[succ_cluster]), ub);
}
int predecessor(node *v, int x, int ub) const {
if (ub <= 1) {
if (x == 1 && v->min == 0)
return 0;
return -1;
}
if (v->max != -1 && x > v->max)
return v->max;
int min_low = minimum(v->cluster[high(x, ub)]);
if (min_low != U && low(x, ub) > min_low) {
return index(
high(x, ub),
predecessor(v->cluster[high(x, ub)], low(x, ub), downsqrt(ub)), ub);
}
int pred_cluster = predecessor(v->summary, high(x, ub), upsqrt(ub));
if (pred_cluster == -1) {
if (v->min != -1 && x > v->min)
return v->min;
return -1;
}
return index(pred_cluster, maximum(v->cluster[pred_cluster]), ub);
}
public:
vEB() : root(nullptr), cnt(0) {}
int size() const { return cnt; }
bool member(int x) const { return member(root, x, __builtin_ctz(U)); }
int minimum() const { return minimum(root); }
int maximum() const { return maximum(root); }
void insert(int x) {
if (!member(x))
root = insert(root, x, __builtin_ctz(U)), cnt++;
}
void erase(int x) {
if (member(x))
root = erase(root, x, __builtin_ctz(U)), cnt--;
}
int successor(int x) const { return successor(root, x, __builtin_ctz(U)); }
int predecessor(int x) const {
return predecessor(root, x, __builtin_ctz(U));
}
};
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, q;
cin >> n;
vEB<> veb;
for (int i = 0; i < n; i++) {
int si;
cin >> si;
veb.insert(si);
}
int res = 0;
cin >> q;
for (int j = 0; j < q; j++) {
int ti;
cin >> ti;
res += veb.member(ti);
}
cout << res << endl;
return 0;
}
|
replace
| 18 | 21 | 18 | 21 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define M 104627
#define NIL (-1)
#define L 14
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;
else
return 0;
}
long long getKey(char str[1]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define M 1046527
#define NIL (-1)
#define L 14
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;
else
return 0;
}
long long getKey(char str[1]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <stdio.h>
#include <string.h>
using namespace std;
#define LIM 519430400
#define LEN 13
char H[LIM][LEN];
int toInt(char str) {
if (str == 'A')
return 1;
else if (str == 'C')
return 2;
else if (str == 'G')
return 3;
else if (str == 'T')
return 4;
else
return 0;
}
long long getKey(char str[]) {
int i, m, p = 1, sum = 0;
for (i = 0; i < strlen(str); i++) {
m = toInt(str[i]);
sum += m * p;
p += 5;
}
return sum;
}
int h1(long long key) { return key % LIM; }
int h2(long long key) { return 1 + (key % (LIM - 1)); }
long long hashValue(long long key, int i) { return h1(key) + i * h2(key); }
int insert(char str[]) {
long long key = getKey(str);
for (int i = 0; i < LIM; i++) {
long long h = hashValue(key, i);
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 1;
}
}
return 0;
}
int find(char str[]) {
long long key = getKey(str);
for (int i = 0; i < LIM; i++) {
long long h = hashValue(key, i);
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int main() {
int n;
char com[6], str[12];
scanf("%d", &n);
while (scanf("%s %s", com, str) != EOF) {
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
using namespace std;
#define LIM 519430400
#define LEN 13
char H[LIM][LEN];
int toInt(char str) {
if (str == 'A')
return 1;
else if (str == 'C')
return 2;
else if (str == 'G')
return 3;
else if (str == 'T')
return 4;
else
return 0;
}
long long getKey(char str[]) {
int i, m, p = 1, sum = 0;
for (i = 0; i < strlen(str); i++) {
m = toInt(str[i]);
sum += m * p;
p *= 5;
}
return sum;
}
int h1(long long key) { return key % LIM; }
int h2(long long key) { return 1 + (key % (LIM - 1)); }
long long hashValue(long long key, int i) { return h1(key) + i * h2(key); }
int insert(char str[]) {
long long key = getKey(str);
for (int i = 0; i < LIM; i++) {
long long h = hashValue(key, i);
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 1;
}
}
return 0;
}
int find(char str[]) {
long long key = getKey(str);
for (int i = 0; i < LIM; i++) {
long long h = hashValue(key, i);
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int main() {
int n;
char com[6], str[12];
scanf("%d", &n);
while (scanf("%s %s", com, str) != EOF) {
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 27 | 28 | 27 | 28 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13
using namespace std;
int translateChar(char ch) {
int ret;
switch (ch) {
case 'A':
ret = 1;
break;
case 'C':
ret = 2;
break;
case 'G':
ret = 3;
break;
case 'T':
ret = 4;
break;
}
return ret;
}
int calc(int num) {
if (num == 0) {
return 1;
} else {
return 4 * calc(num - 1);
}
}
int translateStr(char buf[]) {
int sum = 0;
for (int i = 0; buf[i] != '\0'; i++) {
sum += translateChar(buf[i]) * calc(i);
}
return sum - 1;
}
int main() {
queue<string> Messages;
int n;
scanf("%d", &n);
char order[ORDER_LENGTH], str[STR_LENGTH];
char *check_table = new char[n];
for (int i = 0; i < n; i++) {
scanf("%s %s", order, str);
if (strcmp(order, "insert") == 0) {
check_table[translateStr(str)] = 'Y';
} else {
if (check_table[translateStr(str)] == 'Y') {
Messages.push("yes");
} else {
Messages.push("no");
}
}
}
while (!Messages.empty()) {
cout << Messages.front() << endl;
Messages.pop();
}
delete[] check_table;
}
|
#include <iostream>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13
using namespace std;
int translateChar(char ch) {
int ret;
switch (ch) {
case 'A':
ret = 1;
break;
case 'C':
ret = 2;
break;
case 'G':
ret = 3;
break;
case 'T':
ret = 4;
break;
}
return ret;
}
int calc(int num) {
if (num == 0) {
return 1;
} else {
return 4 * calc(num - 1);
}
}
int translateStr(char buf[]) {
int sum = 0;
for (int i = 0; buf[i] != '\0'; i++) {
sum += translateChar(buf[i]) * calc(i);
}
return sum - 1;
}
int main() {
queue<string> Messages;
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 (strcmp(order, "insert") == 0) {
check_table[translateStr(str)] = 'Y';
} else {
if (check_table[translateStr(str)] == 'Y') {
Messages.push("yes");
} else {
Messages.push("no");
}
}
}
while (!Messages.empty()) {
cout << Messages.front() << endl;
Messages.pop();
}
delete[] check_table;
}
|
replace
| 55 | 56 | 55 | 56 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define rep(i, first, to) for (ll i = first; i < to; ++i)
using namespace std;
typedef long long ll;
struct HashSet {
string data[(int)1e6];
const int MAXN = (int)1e6;
const string INIT = "-1";
HashSet() {
rep(i, 0, MAXN) { data[i] = INIT; }
}
bool find(string s) {
int j = h(s);
// cout << "codefind : " << j << endl;
rep(i, 0, MAXN) {
if (data[j] == INIT)
return false;
if (data[j] == s)
return true;
j = (j + 1) % MAXN;
}
return false;
}
void insert(string s) {
int j = h(s);
// cout << "codeinsert : " << j << endl;
rep(i, 0, MAXN) {
if (data[j] == INIT) {
data[j] = s;
return;
}
j = (j + 1) % MAXN;
}
}
int h(string s) {
int hashcode = 0;
int j = 1;
rep(i, 0, s.size()) {
hashcode += j * h1(s[i]);
j *= 5;
}
hashcode %= MAXN;
// cout << "hashcode : " << hashcode << endl;
return hashcode;
}
int h1(char c) {
if ('A' == c) {
return 1;
} else if ('G' == c) {
return 2;
} else if ('C' == c) {
return 3;
} else if ('T' == c) {
return 4;
}
}
};
int n;
HashSet *mySet = new HashSet();
void solve() {
string op, s;
cin >> n;
rep(i, 0, n) {
cin >> op >> s;
if (op == "insert") {
mySet->insert(s);
} else {
if (mySet->find(s)) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
delete mySet;
}
void test() { cout << pow(5, 12) << endl; }
int main() {
solve();
// test();
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, first, to) for (ll i = first; i < to; ++i)
using namespace std;
typedef long long ll;
struct HashSet {
string data[(int)1e6];
const int MAXN = (int)1e6;
const string INIT = "-1";
HashSet() {
rep(i, 0, MAXN) { data[i] = INIT; }
}
bool find(string s) {
int j = h(s);
// cout << "codefind : " << j << endl;
rep(i, 0, MAXN) {
if (data[j] == INIT)
return false;
if (data[j] == s)
return true;
j = (j + 1) % MAXN;
}
return false;
}
void insert(string s) {
int j = h(s);
// cout << "codeinsert : " << j << endl;
rep(i, 0, MAXN) {
if (data[j] == INIT || data[j] == s) {
data[j] = s;
return;
}
j = (j + 1) % MAXN;
}
}
int h(string s) {
int hashcode = 0;
int j = 1;
rep(i, 0, s.size()) {
hashcode += j * h1(s[i]);
j *= 5;
}
hashcode %= MAXN;
// cout << "hashcode : " << hashcode << endl;
return hashcode;
}
int h1(char c) {
if ('A' == c) {
return 1;
} else if ('G' == c) {
return 2;
} else if ('C' == c) {
return 3;
} else if ('T' == c) {
return 4;
}
}
};
int n;
HashSet *mySet = new HashSet();
void solve() {
string op, s;
cin >> n;
rep(i, 0, n) {
cin >> op >> s;
if (op == "insert") {
mySet->insert(s);
} else {
if (mySet->find(s)) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
delete mySet;
}
void test() { cout << pow(5, 12) << endl; }
int main() {
solve();
// test();
return 0;
}
|
replace
| 30 | 31 | 30 | 31 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <cstdio>
#include <cstring>
using namespace std;
typedef unsigned int U;
#define L 1 << 20
bool HA[L];
char T[256];
int main() {
U n, s, t;
char c;
T['A'] = (char)1, T['C'] = (char)2, T['G'] = (char)3, T['T'] = (char)4;
scanf("%d", &n);
while (getchar() != '\n')
;
for (register U i = 0; i++ < n;) {
s = 0;
t = 1;
bool flag = (c = getchar()) == 'i';
while ((c = getchar()) != ' ')
;
while ((c = T[getchar()]) != 0) {
s += c * t;
t *= 4;
}
if (flag) {
HA[s] = true;
} else {
puts(HA[s] ? "yes" : "no");
}
}
return 0;
}
|
#include <cstdio>
#include <cstring>
using namespace std;
typedef unsigned int U;
#define L 1 << 20 + 1
bool HA[L];
char T[256];
int main() {
U n, s, t;
char c;
T['A'] = (char)1, T['C'] = (char)2, T['G'] = (char)3, T['T'] = (char)4;
scanf("%d", &n);
while (getchar() != '\n')
;
for (register U i = 0; i++ < n;) {
s = 0;
t = 1;
bool flag = (c = getchar()) == 'i';
while ((c = getchar()) != ' ')
;
while ((c = T[getchar()]) != 0) {
s += c * t;
t *= 4;
}
if (flag) {
HA[s] = true;
} else {
puts(HA[s] ? "yes" : "no");
}
}
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p02269
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
auto encodeString = [](const string &str) {
auto encodeChar = [](char c) {
switch (c) {
case 'A':
return 1;
case 'C':
return 2;
case 'G':
return 3;
case 'T':
return 4;
default:
assert(false);
}
};
auto pow = [](auto b, auto e) {
int r{1};
for (auto i = 0; i < e; ++i) {
r *= b;
}
return r;
};
vector<char> v;
transform(begin(str), end(str), back_inserter(v), encodeChar);
int r{0};
for (size_t i = 0; i < v.size(); ++i) {
r += v[i] * pow(5, i);
}
return r;
};
bitset<244140624 + 1> b;
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string instruction;
string s;
cin >> instruction >> s;
if (instruction == "insert") {
b[encodeString(s)] = true;
} else {
if (b[encodeString(s)]) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
auto encodeString = [](const string &str) {
auto encodeChar = [](char c) {
switch (c) {
case 'A':
return 1;
case 'C':
return 2;
case 'G':
return 3;
case 'T':
return 4;
default:
assert(false);
}
};
auto pow = [](auto b, auto e) {
int r{1};
for (auto i = 0; i < e; ++i) {
r *= b;
}
return r;
};
vector<char> v;
transform(begin(str), end(str), back_inserter(v), encodeChar);
int r{0};
for (size_t i = 0; i < v.size(); ++i) {
r += v[i] * pow(5, i);
}
return r;
};
vector<bool> b(244140624 + 1);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string instruction;
string s;
cin >> instruction >> s;
if (instruction == "insert") {
b[encodeString(s)] = true;
} else {
if (b[encodeString(s)]) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
}
|
replace
| 40 | 42 | 40 | 41 |
-11
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
set<string> st;
while (n--) {
string order;
string str;
cin >> order;
cin >> str;
if (order == "insert") {
st.insert(str);
} else {
if (st.find(str) != st.end()) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
return 0;
}
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
set<string> st;
while (n--) {
string order;
string str;
cin >> order;
cin >> str;
if (order == "insert") {
st.insert(str);
} else {
if (st.find(str) != st.end()) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
return 0;
}
|
insert
| 6 | 6 | 6 | 8 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;
int main() {
int n;
cin >> n;
set<string> s;
for (int i = 0; i < n; i++) {
string s1, s2;
cin >> s1 >> s2;
if (s1[0] == 'i')
s.insert(s2);
else {
if (s.find(s2) == s.end())
printf("no\n");
else
printf("yes\n");
}
}
}
|
#include <cstdio>
#include <iostream>
#include <set>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
set<string> s;
for (int i = 0; i < n; i++) {
string s1, s2;
cin >> s1 >> s2;
if (s1[0] == 'i')
s.insert(s2);
else {
if (s.find(s2) == s.end())
printf("no\n");
else
printf("yes\n");
}
}
}
|
replace
| 6 | 7 | 6 | 7 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 8;
#define MOD 1046527
int n;
char H[maxn][15];
int getChar(char ch) { return ch - 'A' + 1; }
ll getValue(char t[]) {
int len = strlen(t);
ll sum = 0, p = 1, i;
for (i = 0; i < len; ++i) {
sum += p * getChar(t[i]);
p *= 5;
}
return sum;
}
ll h1(ll k) { return k % MOD; }
ll h2(ll k) { return 1 + (k % (MOD - 1)); }
int solve_insert(char c[]) {
ll key, i, h;
key = getValue(c);
i = 0;
while (true) {
h = (h1(key) + i * h2(key)) % MOD;
if (strcmp(H[h], c) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], c);
return 0;
}
i++;
}
}
int solve_find(char c[]) {
ll key, i, h;
i = 0;
key = getValue(c);
while (true) {
h = (h1(key) + i * h2(key)) % MOD;
if (strcmp(H[h], c) == 0)
return 1;
else if (strlen(H[h]) == 0) {
return 0;
}
i++;
}
}
int main() {
scanf("%d", &n);
char s[15], t[15];
for (int i = 0; i < n; ++i) {
scanf("%s%s", s, t);
if (s[0] == 'i') {
solve_insert(t);
} else {
if (solve_find(t))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 8;
#define MOD 1046527
int n;
char H[maxn][15];
int getChar(char ch) { return ch - 'A' + 1; }
ll getValue(char t[]) {
int len = strlen(t);
ll sum = 0, p = 1, i;
for (i = 0; i < len; ++i) {
sum += p * getChar(t[i]);
p *= 5;
}
return sum;
}
ll h1(ll k) { return k % MOD; }
ll h2(ll k) { return 1 + (k % (MOD - 1)); }
int solve_insert(char c[]) {
ll key, i, h;
key = getValue(c);
i = 0;
while (true) {
h = (h1(key) + i * h2(key)) % MOD;
if (strcmp(H[h], c) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], c);
return 0;
}
i++;
}
}
int solve_find(char c[]) {
ll key, i, h;
i = 0;
key = getValue(c);
while (true) {
h = (h1(key) + i * h2(key)) % MOD;
if (strcmp(H[h], c) == 0)
return 1;
else if (strlen(H[h]) == 0) {
return 0;
}
i++;
}
}
int main() {
scanf("%d", &n);
char s[15], t[15];
for (int i = 0; i < n; ++i) {
scanf("%s%s", s, t);
if (s[0] == 'i') {
solve_insert(t);
} else {
if (solve_find(t))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
replace
| 15 | 16 | 15 | 16 |
0
| |
p02269
|
C++
|
Runtime Error
|
#include <stdio.h>
#include <string.h>
using namespace std;
#define LIM 1430400
#define LEN 13
char H[LIM][LEN];
int toInt(char str) {
if (str == 'A')
return 1;
else if (str == 'C')
return 2;
else if (str == 'G')
return 3;
else if (str == 'T')
return 4;
else
return 0;
}
long long getKey(char str[]) {
int i, m, p = 1, sum = 0;
for (i = 0; i < strlen(str); i++) {
m = toInt(str[i]);
sum += m * p;
p *= 5;
}
return sum;
}
int h1(long long key) { return key % LIM; }
int h2(long long key) { return 1 + (key % (LIM - 1)); }
long long hashValue(long long key, int i) { return h1(key) + i * h2(key); }
int insert(char str[]) {
long long key = getKey(str);
for (int i = 0; i < LIM; i++) {
long long h = hashValue(key, i);
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 1;
}
}
return 0;
}
int find(char str[]) {
long long key = getKey(str);
for (int i = 0; i < LIM; i++) {
long long h = hashValue(key, i);
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int main() {
int n;
char com[6], str[12];
scanf("%d", &n);
while (scanf("%s %s", com, str) != EOF) {
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
using namespace std;
#define LIM 48828125
#define LEN 13
char H[LIM][LEN];
int toInt(char str) {
if (str == 'A')
return 1;
else if (str == 'C')
return 2;
else if (str == 'G')
return 3;
else if (str == 'T')
return 4;
else
return 0;
}
long long getKey(char str[]) {
int i, m, p = 1, sum = 0;
for (i = 0; i < strlen(str); i++) {
m = toInt(str[i]);
sum += m * p;
p *= 5;
}
return sum;
}
int h1(long long key) { return key % LIM; }
int h2(long long key) { return 1 + (key % (LIM - 1)); }
long long hashValue(long long key, int i) { return h1(key) + i * h2(key); }
int insert(char str[]) {
long long key = getKey(str);
for (int i = 0; i < LIM; i++) {
long long h = hashValue(key, i);
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 1;
}
}
return 0;
}
int find(char str[]) {
long long key = getKey(str);
for (int i = 0; i < LIM; i++) {
long long h = hashValue(key, i);
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int main() {
int n;
char com[6], str[12];
scanf("%d", &n);
while (scanf("%s %s", com, str) != EOF) {
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
typedef int INT;
set<INT> S;
inline INT get(char c) {
char T[5] = "ACGT";
for (INT i = 0; i < 4; ++i) {
if (c == T[i])
return i + 1;
}
return 0;
}
inline INT get(char *s) {
INT n = strlen(s);
INT sum = 0;
INT t = 1;
for (INT i = 0; i < n; ++i) {
sum += get(s[i]) * t;
t *= 4;
}
return sum;
}
inline void insert(char *s) { S.insert(get(s)); }
inline bool find(char *s) { return S.count(get(s)) > 0; }
int main() {
INT n;
while (scanf("%hd", &n) != EOF) {
S.clear();
char cmd[13], data[13];
for (register INT i = 0; i < n; ++i) {
scanf("%s%s", cmd, data);
if (cmd[0] == 'i') {
insert(data);
} else {
puts(find(data) ? "yes" : "no");
}
}
}
return 0;
}
|
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
typedef int INT;
set<INT> S;
inline INT get(char c) {
char T[5] = "ACGT";
for (INT i = 0; i < 4; ++i) {
if (c == T[i])
return i + 1;
}
return 0;
}
inline INT get(char *s) {
INT n = strlen(s);
INT sum = 0;
INT t = 1;
for (INT i = 0; i < n; ++i) {
sum += get(s[i]) * t;
t *= 4;
}
return sum;
}
inline void insert(char *s) { S.insert(get(s)); }
inline bool find(char *s) { return S.count(get(s)) > 0; }
int main() {
INT n;
while (scanf("%d", &n) != EOF) {
S.clear();
char cmd[13], data[13];
for (register INT i = 0; i < n; ++i) {
scanf("%s%s", cmd, data);
if (cmd[0] == 'i') {
insert(data);
} else {
puts(find(data) ? "yes" : "no");
}
}
}
return 0;
}
|
replace
| 35 | 36 | 35 | 36 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
bool dic[1000000] = {0};
long n = 0;
long long k = 0;
string st1, st2;
cin >> n;
for (long i = 0; i < n; i++) {
cin >> st1 >> st2;
k = 0;
for (unsigned int j = 0; j < st2.size(); j++)
switch (st2[j]) {
case 'A':
k += (long long)pow(5, j);
break;
case 'C':
k += (long long)pow(5, j) * 2;
break;
case 'G':
k += (long long)pow(5, j) * 3;
break;
case 'T':
k += (long long)pow(5, j) * 4;
break;
}
if (st1 == "insert")
dic[k] = 1;
else if (st1 == "find") {
if (dic[k] == 1)
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
|
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
bool dic[10000000] = {0};
long n = 0;
long long k = 0;
string st1, st2;
cin >> n;
for (long i = 0; i < n; i++) {
cin >> st1 >> st2;
k = 0;
for (unsigned int j = 0; j < st2.size(); j++)
switch (st2[j]) {
case 'A':
k += (long long)pow(5, j);
break;
case 'C':
k += (long long)pow(5, j) * 2;
break;
case 'G':
k += (long long)pow(5, j) * 3;
break;
case 'T':
k += (long long)pow(5, j) * 4;
break;
}
if (st1 == "insert")
dic[k] = 1;
else if (st1 == "find") {
if (dic[k] == 1)
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
set<string> st;
set<string>::iterator it;
string s1, s2;
int n;
cin >> n;
while (n--) {
cin >> s1 >> s2;
if (s1 == "insert") {
st.insert(s2);
} else {
it = st.find(s2);
if (it != st.end()) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
return 0;
}
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
set<string> st;
set<string>::iterator it;
string s1, s2;
int n;
cin >> n;
while (n--) {
cin >> s1 >> s2;
if (s1 == "insert") {
st.insert(s2);
} else {
it = st.find(s2);
if (it != st.end()) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
return 0;
}
|
insert
| 7 | 7 | 7 | 10 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
// #include <conio.h>
using namespace std;
int main() {
int n;
set<string> list;
string key;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> key;
if (key == "insert") {
cin >> key;
list.insert(key);
} else if (key == "find") {
cin >> key;
if (list.find(key) != list.end())
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
// #include <conio.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
int n;
set<string> list;
string key;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> key;
if (key == "insert") {
cin >> key;
list.insert(key);
} else if (key == "find") {
cin >> key;
if (list.find(key) != list.end())
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
|
insert
| 11 | 11 | 11 | 12 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <cstdio>
#include <iostream>
#include <string.h>
#define M 1046527 // It's a "prime number".
#define L 14 // Why?
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;
else
return 0;
}
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = h1(key) + i * h2(key);
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int n;
scanf("%d", &n);
char str[L], com[9];
for (int i = 0; i < M; i++) {
H[i][0] = '\0';
}
for (int i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else if (com[0] == 'f') {
if (find(str))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <string.h>
#define M 1046527 // It's a "prime number".
#define L 14 // Why?
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;
else
return 0;
}
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int n;
scanf("%d", &n);
char str[L], com[9];
for (int i = 0; i < M; i++) {
H[i][0] = '\0';
}
for (int i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else if (com[0] == 'f') {
if (find(str))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
replace
| 38 | 39 | 38 | 39 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++)
#define REP(i, e) FOR(i, 0, e)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
typedef long long ll;
typedef pair<int, int> PII;
const double EPS = 1e-10;
int n;
int main() {
map<string, bool> d;
string q, s;
scanf("%d ", &n);
for (int i = 0; i < n; i++) {
cin >> q >> s;
// if (q == "insert" && !d.count(s))
if (q == "insert")
d[s] = true;
else if (q == "find") {
// cout << (d.count(s) ? "yes" : "no") << endl;
if (d.count(s))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++)
#define REP(i, e) FOR(i, 0, e)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
typedef long long ll;
typedef pair<int, int> PII;
const double EPS = 1e-10;
int n;
int main() {
map<string, bool> d;
string q, s;
scanf("%d ", &n);
for (int i = 0; i < n; i++) {
char qq[7], ss[13];
scanf("%s%s ", qq, ss);
q = qq;
s = ss;
// cin >> q >> s;
// if (q == "insert" && !d.count(s))
if (q == "insert")
d[s] = true;
else if (q == "find") {
// cout << (d.count(s) ? "yes" : "no") << endl;
if (d.count(s))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
replace
| 23 | 24 | 23 | 28 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define M 104652
#define NIL (-1)
#define L 14
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;
else
return 0;
}
long long getKey(
char str
[]) { //????????§??¬????????????????????¨??????????????????????????????
long long sum = 0, p = 1;
int i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(
int key) { // h2??????????????????????????????????????¨???????????????????????????
return key % M;
}
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, h;
int i;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0) {
return 1;
} else if (strlen(H[h]) == 0) {
return 0;
}
}
}
int insert(char str[]) {
long long key, h;
int i;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0) {
return 1;
} else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
}
int main() {
int n, h, i;
char str[L], com[9];
for (i = 0; i < M; i++) {
H[i][0] = '\0';
}
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define M 1046527
#define NIL (-1)
#define L 14
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;
else
return 0;
}
long long getKey(
char str
[]) { //????????§??¬????????????????????¨??????????????????????????????
long long sum = 0, p = 1;
int i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(
int key) { // h2??????????????????????????????????????¨???????????????????????????
return key % M;
}
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, h;
int i;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0) {
return 1;
} else if (strlen(H[h]) == 0) {
return 0;
}
}
}
int insert(char str[]) {
long long key, h;
int i;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0) {
return 1;
} else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
}
int main() {
int n, h, i;
char str[L], com[9];
for (i = 0; i < M; i++) {
H[i][0] = '\0';
}
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main(void) {
int n;
string o, s;
set<string> set;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> o >> s;
if (o == "insert") {
set.insert(s);
} else {
if (set.find(s) != set.end()) {
cout << "yes" << endl;
} else
cout << "no" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(false);
int n;
string o, s;
set<string> set;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> o >> s;
if (o == "insert") {
set.insert(s);
} else {
if (set.find(s) != set.end()) {
cout << "yes" << endl;
} else
cout << "no" << endl;
}
}
return 0;
}
|
insert
| 5 | 5 | 5 | 6 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main(void) {
int n;
string order, str;
set<string> set;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> order >> str;
if (order == "insert") {
set.insert(str);
} else {
if (set.find(str) != set.end()) {
cout << "yes" << endl;
} else
cout << "no" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
int n;
string order, str;
set<string> set;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> order >> str;
if (order == "insert") {
set.insert(str);
} else {
if (set.find(str) != set.end()) {
cout << "yes" << endl;
} else
cout << "no" << endl;
}
}
return 0;
}
|
insert
| 5 | 5 | 5 | 6 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <stdio.h>
#include <string.h>
#define LEN 14
#define LIM 2000000
char H[LIM][LEN];
int toInt(char c) {
if (c == 'A')
return 1;
else if (c == 'C')
return 2;
else if (c == 'G')
return 3;
else if (c == 'T')
return 4;
else
return 0;
}
int getKey(char str[]) {
int sum = 0, p = 1;
for (int i = 0; i < strlen(str); i++) {
int v = toInt(str[i]);
sum += v * p;
p *= 5;
}
return sum;
}
int h1(int key) { return key % LIM; }
int h2(int key) { return 1 + key % (LIM - 1); }
int hashValue(int key, int i) { return h1(key) + i * h2(key); }
int insert(char str[]) {
int key = getKey(str);
for (int i = 0; i < LIM; i++) {
int h = hashValue(key, i);
if (strcmp(H[h], str) == 0) {
return 1;
} else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 1;
}
}
return 0;
}
int find(char str[]) {
int key = getKey(str);
for (int i = 0; i < LIM; i++) {
int h = hashValue(key, i);
if (strcmp(H[h], str) == 0) {
return 1;
} else if (strlen(H[h]) == 0) {
return 0;
}
}
return 0;
}
int main() {
int n;
char com[7], str[LEN];
scanf("%d", &n);
while (scanf("%s %s", com, str) != EOF) {
if (com[0] == 'i') {
insert(str);
} else if (com[0] == 'f') {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define LEN 14
#define LIM 2000000
char H[LIM][LEN];
int toInt(char c) {
if (c == 'A')
return 1;
else if (c == 'C')
return 2;
else if (c == 'G')
return 3;
else if (c == 'T')
return 4;
else
return 0;
}
int getKey(char str[]) {
int sum = 0, p = 1;
for (int i = 0; i < strlen(str); i++) {
int v = toInt(str[i]);
sum += v * p;
p *= 5;
}
return sum;
}
int h1(int key) { return key % LIM; }
int h2(int key) { return 1 + key % (LIM - 1); }
int hashValue(int key, int i) { return (h1(key) + i * h2(key)) % LIM; }
int insert(char str[]) {
int key = getKey(str);
for (int i = 0; i < LIM; i++) {
int h = hashValue(key, i);
if (strcmp(H[h], str) == 0) {
return 1;
} else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 1;
}
}
return 0;
}
int find(char str[]) {
int key = getKey(str);
for (int i = 0; i < LIM; i++) {
int h = hashValue(key, i);
if (strcmp(H[h], str) == 0) {
return 1;
} else if (strlen(H[h]) == 0) {
return 0;
}
}
return 0;
}
int main() {
int n;
char com[7], str[LEN];
scanf("%d", &n);
while (scanf("%s %s", com, str) != EOF) {
if (com[0] == 'i') {
insert(str);
} else if (com[0] == 'f') {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 33 | 34 | 33 | 34 |
0
| |
p02269
|
C++
|
Runtime Error
|
/*
filename:4_C-Dictionary.c
created on 17.9.2015 by charis
last edited on 17.9.2015 by charis
*/
#include <cstdio>
#include <cstring>
int m;
int getkey(char str[]) {
int sum = 0, p = 1;
for (int k = 0; k < strlen(str); k++) {
if (str[k] == 'A')
sum += p * 1;
else if (str[k] == 'C')
sum += p * 2;
else if (str[k] == 'G')
sum += p * 3;
else if (str[k] == 'T')
sum += p * 4;
p *= 5;
}
return sum;
}
int h1(int key) { return key % m; }
int h2(int key) { return 1 + (key % (m - 1)); }
int h(int key, int i) { return (h1(key) + i * h2(key)) % m; }
void insert(int T[], int key) {
int i = 0;
while (1) {
int j = h(key, i);
if (T[j] == 0) {
T[j] = key;
break;
} else
i++;
}
}
bool search(int T[], int key) {
int i = 0;
while (1) {
int j = h(key, i);
if (T[j] == key)
return true;
else if (T[j] == 0 || i >= m)
return false;
else
i++;
}
}
int main() {
int n;
scanf("%d", &n);
m = 1000000;
int T[m];
for (int k = 0; k < m; k++) {
T[k] = 0;
}
for (int k = 0; k < n; k++) {
char com[9], str[13];
scanf("%s %s", com, str);
int key = getkey(str);
if (com[0] == 'i')
insert(T, key);
else if (com[0] == 'f') {
if (search(T, key))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
/*
filename:4_C-Dictionary.c
created on 17.9.2015 by charis
last edited on 17.9.2015 by charis
*/
#include <cstdio>
#include <cstring>
int m;
int getkey(char str[]) {
int sum = 0, p = 1;
for (int k = 0; k < strlen(str); k++) {
if (str[k] == 'A')
sum += p * 1;
else if (str[k] == 'C')
sum += p * 2;
else if (str[k] == 'G')
sum += p * 3;
else if (str[k] == 'T')
sum += p * 4;
p *= 5;
}
return sum;
}
int h1(int key) { return key % m; }
int h2(int key) { return 1 + (key % (m - 1)); }
int h(int key, int i) { return (h1(key) + i * h2(key)) % m; }
void insert(int T[], int key) {
int i = 0;
while (1) {
int j = h(key, i);
if (T[j] == 0) {
T[j] = key;
break;
} else
i++;
}
}
bool search(int T[], int key) {
int i = 0;
while (1) {
int j = h(key, i);
if (T[j] == key)
return true;
else if (T[j] == 0 || i >= m)
return false;
else
i++;
}
}
int main() {
int n;
scanf("%d", &n);
m = 1046527;
int T[m];
for (int k = 0; k < m; k++) {
T[k] = 0;
}
for (int k = 0; k < n; k++) {
char com[9], str[13];
scanf("%s %s", com, str);
int key = getkey(str);
if (com[0] == 'i')
insert(T, key);
else if (com[0] == 'f') {
if (search(T, key))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
replace
| 56 | 57 | 56 | 57 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <typeinfo>
#include <vector>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);
/*
class Target
{
public:
vector <string> draw(int n)
{
}
};
*/
int main() {
int n;
char str[10], com[13];
map<string, bool> T;
cin >> n;
REP(n) {
cin >> com >> str;
if (com[0] == 'i') {
T[string(str)] = true;
} else {
if (T[string(str)])
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
void trace(int A[], int N) {
REP(N) {
if (i > 0)
cout << " ";
cout << A[i];
}
cout << endl;
}
double distanceAB(double xa, double ya, double xb, double yb) {
return sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <typeinfo>
#include <vector>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;
double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);
/*
class Target
{
public:
vector <string> draw(int n)
{
}
};
*/
int main() {
int n;
char str[10], com[13];
map<string, bool> T;
cin >> n;
REP(n) {
scanf("%s%s", com, str);
if (com[0] == 'i') {
T[string(str)] = true;
} else {
if (T[string(str)])
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
void trace(int A[], int N) {
REP(N) {
if (i > 0)
cout << " ";
cout << A[i];
}
cout << endl;
}
double distanceAB(double xa, double ya, double xb, double yb) {
return sqrt((xb - xa) * (xb - xa) + (yb - ya) * (yb - ya));
}
|
replace
| 44 | 45 | 44 | 45 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <stdio.h>
#include <string.h>
int n, r[128], t[13];
bool used[22370000];
char com[8], s[14];
int main() {
scanf("%d", &n);
r[65] = 1, r[67] = 2, r[71] = 3;
for (int i = 2; i < 12; i++)
t[i] = t[i - 1] + 1 << (2 * i - 2);
for (int i = 0; i < n; i++) {
scanf("%s %s", com, s);
int h = 0, l = strlen(s);
for (int j = 0; j < l; j++)
h = h * 4 + r[s[j]];
if (com[0] == 105)
used[h + t[l]] = true;
else
puts(used[h + t[l]] ? "yes" : "no");
}
}
|
#include <stdio.h>
#include <string.h>
int n, r[128], t[13];
bool used[22370000];
char com[8], s[14];
int main() {
scanf("%d", &n);
r[65] = 1, r[67] = 2, r[71] = 3;
for (int i = 2; i < 13; i++)
t[i] = t[i - 1] + (1 << (2 * i - 2));
for (int i = 0; i < n; i++) {
scanf("%s %s", com, s);
int h = 0, l = strlen(s);
for (int j = 0; j < l; j++)
h = h * 4 + r[s[j]];
if (com[0] == 105)
used[h + t[l]] = true;
else
puts(used[h + t[l]] ? "yes" : "no");
}
}
|
replace
| 8 | 10 | 8 | 10 |
0
| |
p02269
|
C++
|
Runtime Error
|
//
// main.cpp
// dictionary
//
// Created by ???????????? on 2017/10/06.
// Copyright ?? 2017 ????????????. All rights reserved.
//
#include <cmath>
#include <cstring>
#include <iostream>
#include <stdio.h>
#define NIL (0)
using namespace std;
int m = 10000000;
int char_to_int(char str) {
if (str == 'A') {
return 1;
} else if (str == 'C') {
return 2;
} else if (str == 'G') {
return 3;
} else if (str == 'T') {
return 4;
}
cout << "Unexpected input given" << endl;
return 0;
}
long long get_key(char string[]) {
long long key_str = 0, p = 1;
size_t n = strlen(string);
for (int i = 0; i < n; i++) {
key_str += p * char_to_int(string[i]);
p *= 5;
}
return key_str;
}
int h1(int key) { return key % m; }
int h2(int key) { return 1 + (key % (m - 1)); }
int h(int key, int i) { return (h1(key) + i * h2(key)) % m; }
void insert(int T[], int key) {
int i = 0;
while (true) {
int j = h(key, i);
if (T[j] == NIL) {
T[j] = key;
break;
} else {
i++;
}
}
}
bool search(int T[], int key) {
int i = 0;
while (true) {
int j = h(key, i);
if (T[j] == key) {
return true;
} else if (T[j] == NIL || i > m) {
return false;
} else {
i++;
}
}
}
int main(int argc, const char *argv[]) {
int n, i;
long long key;
char com[10], string[10];
int T[m];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, string);
key = get_key(string);
if (com[0] == 'i') {
insert(T, key);
} else if (com[0] == 'f') {
if (search(T, key)) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
} else {
cout << "Got unexpected command" << endl;
}
}
return 0;
}
|
//
// main.cpp
// dictionary
//
// Created by ???????????? on 2017/10/06.
// Copyright ?? 2017 ????????????. All rights reserved.
//
#include <cmath>
#include <cstring>
#include <iostream>
#include <stdio.h>
#define NIL (0)
using namespace std;
int m = 1046527;
int char_to_int(char str) {
if (str == 'A') {
return 1;
} else if (str == 'C') {
return 2;
} else if (str == 'G') {
return 3;
} else if (str == 'T') {
return 4;
}
cout << "Unexpected input given" << endl;
return 0;
}
long long get_key(char string[]) {
long long key_str = 0, p = 1;
size_t n = strlen(string);
for (int i = 0; i < n; i++) {
key_str += p * char_to_int(string[i]);
p *= 5;
}
return key_str;
}
int h1(int key) { return key % m; }
int h2(int key) { return 1 + (key % (m - 1)); }
int h(int key, int i) { return (h1(key) + i * h2(key)) % m; }
void insert(int T[], int key) {
int i = 0;
while (true) {
int j = h(key, i);
if (T[j] == NIL) {
T[j] = key;
break;
} else {
i++;
}
}
}
bool search(int T[], int key) {
int i = 0;
while (true) {
int j = h(key, i);
if (T[j] == key) {
return true;
} else if (T[j] == NIL || i > m) {
return false;
} else {
i++;
}
}
}
int main(int argc, const char *argv[]) {
int n, i;
long long key;
char com[10], string[10];
int T[m];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, string);
key = get_key(string);
if (com[0] == 'i') {
insert(T, key);
} else if (com[0] == 'f') {
if (search(T, key)) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
} else {
cout << "Got unexpected command" << endl;
}
}
return 0;
}
|
replace
| 17 | 18 | 17 | 18 |
-11
| |
p02269
|
C++
|
Runtime Error
|
//
// main.cpp
// dictionary
//
// Created by ???????????? on 2017/10/06.
// Copyright ?? 2017 ????????????. All rights reserved.
//
#include <cmath>
#include <cstring>
#include <iostream>
#include <stdio.h>
#define NIL (0)
using namespace std;
int m = 1000107;
int char_to_int(char str) {
if (str == 'A') {
return 1;
} else if (str == 'C') {
return 2;
} else if (str == 'G') {
return 3;
} else if (str == 'T') {
return 4;
}
cout << "Unexpected input given" << endl;
return 0;
}
long long get_key(char string[]) {
long long key_str = 0, p = 1;
size_t n = strlen(string);
for (int i = 0; i < n; i++) {
key_str += p * char_to_int(string[i]);
p *= 5;
}
return key_str;
}
int h1(int key) { return key % m; }
int h2(int key) { return 1 + (key % (m - 1)); }
int h(int key, int i) { return (h1(key) + i * h2(key)) % m; }
void insert(int T[], int key) {
int i = 0;
while (true) {
int j = h(key, i);
if (T[j] == NIL) {
T[j] = key;
break;
} else {
i++;
}
}
}
bool search(int T[], int key) {
int i = 0;
while (true) {
int j = h(key, i);
if (T[j] == key) {
return true;
} else if (T[j] == NIL || i > m) {
return false;
} else {
i++;
}
}
}
int main(int argc, const char *argv[]) {
int n, i;
long long key;
char com[10], string[10];
int T[m];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, string);
key = get_key(string);
if (com[0] == 'i') {
insert(T, key);
} else if (com[0] == 'f') {
if (search(T, key)) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
} else {
cout << "Got unexpected command" << endl;
}
}
return 0;
}
|
//
// main.cpp
// dictionary
//
// Created by ???????????? on 2017/10/06.
// Copyright ?? 2017 ????????????. All rights reserved.
//
#include <cmath>
#include <cstring>
#include <iostream>
#include <stdio.h>
#define NIL (0)
using namespace std;
int m = 1000207;
int char_to_int(char str) {
if (str == 'A') {
return 1;
} else if (str == 'C') {
return 2;
} else if (str == 'G') {
return 3;
} else if (str == 'T') {
return 4;
}
cout << "Unexpected input given" << endl;
return 0;
}
long long get_key(char string[]) {
long long key_str = 0, p = 1;
size_t n = strlen(string);
for (int i = 0; i < n; i++) {
key_str += p * char_to_int(string[i]);
p *= 5;
}
return key_str;
}
int h1(int key) { return key % m; }
int h2(int key) { return 1 + (key % (m - 1)); }
int h(int key, int i) { return (h1(key) + i * h2(key)) % m; }
void insert(int T[], int key) {
int i = 0;
while (true) {
int j = h(key, i);
if (T[j] == NIL) {
T[j] = key;
break;
} else {
i++;
}
}
}
bool search(int T[], int key) {
int i = 0;
while (true) {
int j = h(key, i);
if (T[j] == key) {
return true;
} else if (T[j] == NIL || i > m) {
return false;
} else {
i++;
}
}
}
int main(int argc, const char *argv[]) {
int n, i;
long long key;
char com[10], string[10];
int T[m];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, string);
key = get_key(string);
if (com[0] == 'i') {
insert(T, key);
} else if (com[0] == 'f') {
if (search(T, key)) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
} else {
cout << "Got unexpected command" << endl;
}
}
return 0;
}
|
replace
| 17 | 18 | 17 | 18 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <vector>
#define SIZE 1000039
using namespace std;
string hashTable[SIZE];
int hashValue(string str) {
int res = 0;
int v = 1;
for (int i = 0; i < str.length(); i++) {
res += v * (str[i] - '0');
v *= 7;
}
return res;
}
int main(void) {
for (int i = 0; i < SIZE; i++)
hashTable[i] = "";
int n;
cin >> n;
while (n--) {
string query, str;
cin >> query >> str;
if (query == "insert") {
int hash = hashValue(str);
int place = hash % SIZE;
int v = 1;
while (hashTable[place] != "") {
place = (hash % SIZE + v * (1 + hash % (SIZE - 1))) % SIZE;
v++;
}
hashTable[place] = str;
}
if (query == "find") {
int hash = hashValue(str);
int place = hash % SIZE;
int v = 1;
bool yes = true;
while (hashTable[place] != str) {
if (hashTable[place] == "") {
yes = false;
break;
}
place = (hash % SIZE + v * (1 + hash % (SIZE - 1))) % SIZE;
v++;
}
if (yes)
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
|
#include <iostream>
#include <vector>
#define SIZE 1000039
using namespace std;
string hashTable[SIZE];
int hashValue(string str) {
int res = 0;
int v = 1;
for (int i = 0; i < str.length(); i++) {
res += v * (str[i] - '0');
v *= 7;
}
return res;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
for (int i = 0; i < SIZE; i++)
hashTable[i] = "";
int n;
cin >> n;
while (n--) {
string query, str;
cin >> query >> str;
if (query == "insert") {
int hash = hashValue(str);
int place = hash % SIZE;
int v = 1;
while (hashTable[place] != "") {
place = (hash % SIZE + v * (1 + hash % (SIZE - 1))) % SIZE;
v++;
}
hashTable[place] = str;
}
if (query == "find") {
int hash = hashValue(str);
int place = hash % SIZE;
int v = 1;
bool yes = true;
while (hashTable[place] != str) {
if (hashTable[place] == "") {
yes = false;
break;
}
place = (hash % SIZE + v * (1 + hash % (SIZE - 1))) % SIZE;
v++;
}
if (yes)
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
|
insert
| 18 | 18 | 18 | 20 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <string.h>
using namespace std;
const int M = 1000003;
const int L = 12;
char dict[M][L];
int h1(long key) { return key % M; }
int h2(long key) { return 1 + key % (M - 1); }
int h(long key, int i) { return (h1(key) + i * h2(key)) % M; }
long strToKey(char str[]) {
long result = 0;
int length = strlen(str);
for (int i = 0; i < length; i++) {
// Because there is only 4 kind of letters
result *= 5;
switch (str[i]) {
case 'A':
result += 1;
break;
case 'C':
result += 2;
break;
case 'G':
result += 3;
break;
case 'T':
result += 4;
break;
}
}
return result;
}
int insert(char str[]) {
long key = strToKey(str);
int i = 0;
int index = h(key, i);
while (dict[index][0] != '\0') {
i += 1;
index = h(key, i);
}
strcpy(dict[index], str);
return 0;
}
int find(char str[]) {
long key = strToKey(str);
int i = 0;
int index = h(key, i);
while (dict[index][0] != '\0') {
if (strcmp(dict[index], str) == 0) {
return index;
}
}
return -1;
}
int main() {
for (int i = 0; i < M; i++) {
dict[M][0] = '\0';
}
int n;
cin >> n;
char cmd[6];
char str[L];
for (int i = 0; i < n; i++) {
cin >> cmd >> str;
switch (cmd[0]) {
case 'i':
insert(str);
break;
case 'f':
if (find(str) >= 0) {
cout << "yes\n";
} else {
cout << "no\n";
}
break;
}
}
}
|
#include <iostream>
#include <string.h>
using namespace std;
const int M = 1000003;
const int L = 12;
char dict[M][L];
int h1(long key) { return key % M; }
int h2(long key) { return 1 + key % (M - 1); }
int h(long key, int i) { return (h1(key) + i * h2(key)) % M; }
long strToKey(char str[]) {
long result = 0;
int length = strlen(str);
for (int i = 0; i < length; i++) {
// Because there is only 4 kind of letters
result *= 5;
switch (str[i]) {
case 'A':
result += 1;
break;
case 'C':
result += 2;
break;
case 'G':
result += 3;
break;
case 'T':
result += 4;
break;
}
}
return result;
}
int insert(char str[]) {
long key = strToKey(str);
int i = 0;
int index = h(key, i);
while (dict[index][0] != '\0') {
i += 1;
index = h(key, i);
}
strcpy(dict[index], str);
return 0;
}
int find(char str[]) {
long key = strToKey(str);
int i = 0;
int index = h(key, i);
while (dict[index][0] != '\0') {
if (strcmp(dict[index], str) == 0) {
return index;
} else {
i += 1;
index = h(key, i);
}
}
return -1;
}
int main() {
for (int i = 0; i < M; i++) {
dict[M][0] = '\0';
}
int n;
cin >> n;
char cmd[6];
char str[L];
for (int i = 0; i < n; i++) {
cin >> cmd >> str;
switch (cmd[0]) {
case 'i':
insert(str);
break;
case 'f':
if (find(str) >= 0) {
cout << "yes\n";
} else {
cout << "no\n";
}
break;
}
}
}
|
insert
| 63 | 63 | 63 | 66 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
// #include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#pragma warning(disable : 4018)
#pragma warning(disable : 4244)
#pragma warning(disable : 4996)
using namespace std;
typedef long long int lint;
//***** Main Program *****
vector<bool> dictionary((int)pow(4, 10), false);
int main() {
int n;
cin >> n;
Loop(i, n) {
char cquery[10], cword[15];
scanf("%s %s", cquery, cword);
lint j = 0, k = 1, key = 0;
while (cword[j] != '\0') {
if (cword[j] == 'A')
key += 1 * k;
else if (cword[j] == 'T')
key += 2 * k;
else if (cword[j] == 'G')
key += 3 * k;
else
key += 4 * k;
k *= 4;
j++;
}
if (cquery[0] == 'i') {
dictionary[key - 1] = true;
} else {
bool judge = dictionary[key - 1];
if (judge)
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
// #include "toollib.h"
// #include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for (int i = 0; i < (int)n; i++)
#pragma warning(disable : 4018)
#pragma warning(disable : 4244)
#pragma warning(disable : 4996)
using namespace std;
typedef long long int lint;
//***** Main Program *****
vector<bool> dictionary((int)pow(4, 12), false);
int main() {
int n;
cin >> n;
Loop(i, n) {
char cquery[10], cword[15];
scanf("%s %s", cquery, cword);
lint j = 0, k = 1, key = 0;
while (cword[j] != '\0') {
if (cword[j] == 'A')
key += 1 * k;
else if (cword[j] == 'T')
key += 2 * k;
else if (cword[j] == 'G')
key += 3 * k;
else
key += 4 * k;
k *= 4;
j++;
}
if (cquery[0] == 'i') {
dictionary[key - 1] = true;
} else {
bool judge = dictionary[key - 1];
if (judge)
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
replace
| 29 | 30 | 29 | 30 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
const int C = 1046527;
char baca[C][13];
int hs(int key, int i) { return (key % C + i * (1 + key % (C - 1))) % C; }
int cToI(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;
else
return 0;
}
int getKey(string tmp) {
int sum = 0, p = 1, l = tmp.length();
for (int i = 0; i < l; i++) {
sum += p * cToI(tmp[i]);
}
return sum;
}
void ins(string str) {
int key = getKey(str);
for (int i = 0; i < C; i++) {
int h = hs(key, i);
if (strlen(baca[h]) == 0) {
strcpy(baca[h], str.c_str());
break;
}
}
}
int find(string str) {
int key = getKey(str);
for (int i = 0;; i++) {
int h = hs(key, i);
if (strlen(baca[h]) == 0) {
return 0;
} else if (strcmp(baca[h], str.c_str()) == 0) {
return 1;
}
}
}
int main() {
ios::sync_with_stdio(false);
int cnt;
cin >> cnt;
string tmp;
string key;
for (int i = 0; i < cnt; i++) {
cin >> tmp >> key;
if (tmp[0] == 'i') {
ins(key);
} else {
find(key) == 1 ? cout << "yes" << endl : cout << "no" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int C = 1046527;
char baca[C][13];
int hs(int key, int i) { return (key % C + i * (1 + key % (C - 1))) % C; }
int cToI(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;
else
return 0;
}
int getKey(string tmp) {
int sum = 0, p = 1, l = tmp.length();
for (int i = 0; i < l; i++) {
sum += p * cToI(tmp[i]);
p *= 5;
}
return sum;
}
void ins(string str) {
int key = getKey(str);
for (int i = 0; i < C; i++) {
int h = hs(key, i);
if (strlen(baca[h]) == 0) {
strcpy(baca[h], str.c_str());
break;
}
}
}
int find(string str) {
int key = getKey(str);
for (int i = 0;; i++) {
int h = hs(key, i);
if (strlen(baca[h]) == 0) {
return 0;
} else if (strcmp(baca[h], str.c_str()) == 0) {
return 1;
}
}
}
int main() {
ios::sync_with_stdio(false);
int cnt;
cin >> cnt;
string tmp;
string key;
for (int i = 0; i < cnt; i++) {
cin >> tmp >> key;
if (tmp[0] == 'i') {
ins(key);
} else {
find(key) == 1 ? cout << "yes" << endl : cout << "no" << endl;
}
}
return 0;
}
|
insert
| 24 | 24 | 24 | 25 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <stdio.h>
#include <string.h>
#define M 122222
#define L 14
char H[M][L]; /* Hash Table */
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (int i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define M 1006000
#define L 14
char H[M][L]; /* Hash Table */
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (int i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <stdio.h>
#include <string.h>
#define M 1046527
#define NIL (-1)
#define L 14
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;
else
return 0;
}
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p * 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + key % (M - 1); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define M 1046527
#define NIL (-1)
#define L 14
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;
else
return 0;
}
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + key % (M - 1); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 25 | 26 | 25 | 26 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <iostream>
#include <string>
#include <vector>
#define M 1000000
std::vector<std::vector<std::string>> dic(M);
int hash(char ch) {
if (ch == 'A')
return 1;
if (ch == 'C')
return 2;
if (ch == 'G')
return 3;
if (ch == 'T')
return 4;
return 0;
}
long long key(std::string str) {
long long v = 0;
int b = 1, n = str.size();
for (int i = 0; i < n; i++) {
v += b * (hash(str[i]));
b *= 5;
}
return v;
}
int find(std::string str) {
std::vector<std::string> s;
s = dic[key(str)];
int n = s.size();
for (int i = 0; i < n; i++) {
if (s[i] == str)
return 1;
}
return 0;
}
void insert(std::string str) { dic[key(str)].push_back(str); }
int main() {
int n;
std::cin >> n;
for (int i = 0; i < n; i++) {
std::string com, str;
std::cin >> com;
std::cin >> str;
if (com[0] == 'i')
insert(str);
else if (find(str))
std::cout << "yes" << '\n';
else
std::cout << "no" << '\n';
}
return 0;
}
|
#include <iostream>
#include <string>
#include <vector>
#define M 1000000
std::vector<std::vector<std::string>> dic(M);
int hash(char ch) {
if (ch == 'A')
return 1;
if (ch == 'C')
return 2;
if (ch == 'G')
return 3;
if (ch == 'T')
return 4;
return 0;
}
long long key(std::string str) {
long long v = 0;
int b = 1, n = str.size();
for (int i = 0; i < n; i++) {
v += b * (hash(str[i]));
b *= 5;
}
return v % M;
}
int find(std::string str) {
std::vector<std::string> s;
s = dic[key(str)];
int n = s.size();
for (int i = 0; i < n; i++) {
if (s[i] == str)
return 1;
}
return 0;
}
void insert(std::string str) { dic[key(str)].push_back(str); }
int main() {
int n;
std::cin >> n;
for (int i = 0; i < n; i++) {
std::string com, str;
std::cin >> com;
std::cin >> str;
if (com[0] == 'i')
insert(str);
else if (find(str))
std::cout << "yes" << '\n';
else
std::cout << "no" << '\n';
}
return 0;
}
|
replace
| 24 | 25 | 24 | 25 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
/*
//alds1_4_c:Dictionary
//算法:开放地址法散列表
//Time: 2018/1/8 星期一
*/
#include <stdio.h>
#include <string.h>
const int M = 1000003;
const int L = 14;
char H[M][L];
// 对于每个字符返回的定义值
int getChar(char ch) {
if (ch == 'A')
return 1;
if (ch == 'C')
return 2;
if (ch == 'D')
return 3;
if (ch == 'T')
return 4;
return 0;
}
// 对于字符串返回的初始散列值
long long getKey(char str[]) {
long long len = strlen(str), sum = 0, p = 1;
for (int i = 0; i < len; ++i) {
sum += p * getChar(str[i]);
// 每次获取定义值后p*5,相当于转换成五进制,不会冲突
p *= 5;
}
return sum;
}
// 开放式散列值计算式: h(k,i)=(h1(k)+i*h2(k))%M
int h1(int key) { return key % M; }
// 为了保证不会递归冲突(即往下算结果始终相同),必须使h2(key)与M互素
int h2(int key) { return (key % (M - 1)); }
// 查找
//-1表示找到
// h表示找到第一个可插入点
int find(char str[]) {
long long key = getKey(str), i, h;
for (i = 0;; ++i) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return -1;
else if (strlen(H[h]) == 0)
return h;
}
return 0;
}
// 插入
void insert(char str[]) {
int key = find(str);
if (key != -1)
strcpy(H[key], str);
}
int main() {
for (int i = 0; i < M; ++i)
H[M][0] = '\0';
char str[L], com[L];
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str) == -1)
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
/*
//alds1_4_c:Dictionary
//算法:开放地址法散列表
//Time: 2018/1/8 星期一
*/
#include <stdio.h>
#include <string.h>
const int M = 1000003;
const int L = 14;
char H[M][L];
// 对于每个字符返回的定义值
int getChar(char ch) {
if (ch == 'A')
return 1;
if (ch == 'C')
return 2;
if (ch == 'D')
return 3;
if (ch == 'T')
return 4;
return 0;
}
// 对于字符串返回的初始散列值
long long getKey(char str[]) {
long long len = strlen(str), sum = 0, p = 1;
for (int i = 0; i < len; ++i) {
sum += p * getChar(str[i]);
// 每次获取定义值后p*5,相当于转换成五进制,不会冲突
p *= 5;
}
return sum;
}
// 开放式散列值计算式: h(k,i)=(h1(k)+i*h2(k))%M
int h1(int key) { return key % M; }
// 为了保证不会递归冲突(即往下算结果始终相同),必须使h2(key)与M互素
// TLE最好的情况就是改这个函数= =
// 目前可以AC的: 1+(key%(M-1))
//(1+key)%(M-1)
int h2(int key) { return (1 + key) % (M - 1); }
// 查找
//-1表示找到
// h表示找到第一个可插入点
int find(char str[]) {
long long key = getKey(str), i, h;
for (i = 0;; ++i) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return -1;
else if (strlen(H[h]) == 0)
return h;
}
return 0;
}
// 插入
void insert(char str[]) {
int key = find(str);
if (key != -1)
strcpy(H[key], str);
}
int main() {
for (int i = 0; i < M; ++i)
H[M][0] = '\0';
char str[L], com[L];
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str) == -1)
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
replace
| 39 | 40 | 39 | 43 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <set>
#include <string>
int main() {
std::set<std::string> dic;
int n;
std::cin >> n;
for (int i = 0; i < n; ++i) {
std::string command, str;
std::cin >> command >> str;
if (command == "insert") {
dic.insert(str);
} else if (command == "find") {
std::cout << (dic.find(str) != dic.end() ? "yes" : "no") << std::endl;
}
}
return 0;
}
|
#include <iostream>
#include <set>
#include <string>
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::set<std::string> dic;
int n;
std::cin >> n;
for (int i = 0; i < n; ++i) {
std::string command, str;
std::cin >> command >> str;
if (command == "insert") {
dic.insert(str);
} else if (command == "find") {
std::cout << (dic.find(str) != dic.end() ? "yes" : "no") << std::endl;
}
}
return 0;
}
|
insert
| 5 | 5 | 5 | 7 |
TLE
| |
p02269
|
C++
|
Memory Limit Exceeded
|
#include <stdio.h>
#include <string.h>
#define M 20000000
#define L 14
char H[M][L]; /* Hash Table */
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (int i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define M 2000000
#define L 14
char H[M][L]; /* Hash Table */
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (int i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
MLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define PUSH(n, v) \
for (int i = 0; i < (n); i++) { \
int j; \
cin >> j; \
v.push_back(j); \
}
#define ALL(v) v.begin(), v.end()
int getint(char c) {
if (c == 'A')
return 1;
else if (c == 'C')
return 2;
else if (c == 'G')
return 3;
else
return 4;
}
int getint(string s) {
int j = 1;
int a = 0;
REP(i, s.size()) {
a += j * getint(s[i]);
j *= 5;
}
return a;
}
int main() {
int n;
cin >> n;
set<int> st;
REP(i, n) {
string s, t;
cin >> s >> t;
int h = getint(t);
if (s == "insert")
st.insert(h);
else {
if (st.find(h) != st.end())
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define PUSH(n, v) \
for (int i = 0; i < (n); i++) { \
int j; \
cin >> j; \
v.push_back(j); \
}
#define ALL(v) v.begin(), v.end()
int getint(char c) {
if (c == 'A')
return 1;
else if (c == 'C')
return 2;
else if (c == 'G')
return 3;
else
return 4;
}
int getint(string s) {
int j = 1;
int a = 0;
REP(i, s.size()) {
a += j * getint(s[i]);
j *= 5;
}
return a;
}
int main() {
int n;
cin >> n;
set<int> st;
REP(i, n) {
string s, t;
cin >> s >> t;
int h = getint(t);
if (s[0] == 'i')
st.insert(h);
else {
if (st.find(h) != st.end())
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
|
replace
| 49 | 50 | 49 | 50 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define M 1046527
using namespace std;
long long h1(long long key) { return key % M; }
long long h2(long long key) { return 1 + (key % (M - 1)); }
long long getNum(char c) {
if (c == 'A')
return 1;
if (c == 'C')
return 2;
if (c == 'G')
return 3;
if (c == 'T')
return 4;
return 0;
}
long long getValue(char *s) {
long long i = 0, value = 0;
while (s[i]) {
value = value * 10 + getNum(s[i]);
i++;
}
return value;
}
char s[1000006][13], word[13], order[10];
long long n, key, value;
int main() {
cin >> n;
for (long long i = 0; i < 1000006; i++)
s[i][0] = 0;
for (long long i = 0; i < n; i++) {
scanf("%s %s", order, word);
value = getValue(word);
if (order[0] == 'i') {
long long k = 0;
while (true) {
key = (h1(value) + k * h2(value)) % M;
if (strcmp(s[key], word) == 0) {
break;
} else if (strlen(s[key]) == 0) {
strcpy(s[key], word);
break;
}
k++;
}
} else {
long long k = 0;
while (true) {
key = (h1(value) + k * h2(value)) % M;
if (strcmp(s[key], word) == 0) {
cout << "yes\n";
break;
} else if (strlen(s[key]) == 0) {
cout << "no\n";
break;
}
k++;
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define M 1046527
using namespace std;
long long h1(long long key) { return key % M; }
long long h2(long long key) { return 1 + (key % (M - 1)); }
long long getNum(char c) {
if (c == 'A')
return 1;
if (c == 'C')
return 2;
if (c == 'G')
return 3;
if (c == 'T')
return 4;
return 0;
}
long long getValue(char *s) {
long long i = 0, value = 0;
while (s[i]) {
value = value * 10 + getNum(s[i]);
i++;
}
return value;
}
char s[1046527][13], word[13], order[10];
long long n, key, value;
int main() {
cin >> n;
for (long long i = 0; i < 1000006; i++)
s[i][0] = 0;
for (long long i = 0; i < n; i++) {
scanf("%s %s", order, word);
value = getValue(word);
if (order[0] == 'i') {
long long k = 0;
while (true) {
key = (h1(value) + k * h2(value)) % M;
if (strcmp(s[key], word) == 0) {
break;
} else if (strlen(s[key]) == 0) {
strcpy(s[key], word);
break;
}
k++;
}
} else {
long long k = 0;
while (true) {
key = (h1(value) + k * h2(value)) % M;
if (strcmp(s[key], word) == 0) {
cout << "yes\n";
break;
} else if (strlen(s[key]) == 0) {
cout << "no\n";
break;
}
k++;
}
}
}
return 0;
}
|
replace
| 24 | 25 | 24 | 25 |
0
| |
p02269
|
C++
|
Runtime Error
|
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const unsigned long M = 1046527;
const int L = 14;
char H[M][L];
long long 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;
else
return 0;
}
long long getKey(char str[]) {
long long sum = 0, p = 1;
for (int i = 0; i < strlen(str); ++i) {
sum += p * getChar(str[i]);
p *= 5;
}
return sum;
}
int h1(long long key) { return key % M; }
int h2(long long key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, h;
key = getKey(str);
for (long long i = 0;; ++i) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
}
int insert(char str[]) {
long long key, h;
key = getKey(str);
for (long long i = 0;; ++i) {
h = (h1(key) + i * h2(key));
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
}
int main() {
for (int i = 0; i < M; ++i)
H[i][0] = '\0';
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
char cmd[L];
char wrd[L];
scanf("%s %s", cmd, wrd);
if (cmd[0] == 'i') {
insert(wrd);
} else {
cout << (find(wrd) ? "yes" : "no") << endl;
}
}
return 0;
}
|
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const unsigned long M = 1046527;
const int L = 14;
char H[M][L];
long long 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;
else
return 0;
}
long long getKey(char str[]) {
long long sum = 0, p = 1;
for (int i = 0; i < strlen(str); ++i) {
sum += p * getChar(str[i]);
p *= 5;
}
return sum;
}
int h1(long long key) { return key % M; }
int h2(long long key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, h;
key = getKey(str);
for (long long i = 0;; ++i) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
}
int insert(char str[]) {
long long key, h;
key = getKey(str);
for (long long i = 0;; ++i) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
}
int main() {
for (int i = 0; i < M; ++i)
H[i][0] = '\0';
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
char cmd[L];
char wrd[L];
scanf("%s %s", cmd, wrd);
if (cmd[0] == 'i') {
insert(wrd);
} else {
cout << (find(wrd) ? "yes" : "no") << endl;
}
}
return 0;
}
|
replace
| 52 | 53 | 52 | 53 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
set<string> dict;
for (int i = 0; i < N; ++i) {
string command;
string val;
cin >> command;
cin >> val;
if (command[0] == 'i') {
// insert
dict.insert(val);
} else {
// find
if (dict.find(val) != dict.end()) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int N;
cin >> N;
set<string> dict;
for (int i = 0; i < N; ++i) {
string command;
string val;
cin >> command;
cin >> val;
if (command[0] == 'i') {
// insert
dict.insert(val);
} else {
// find
if (dict.find(val) != dict.end()) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
return 0;
}
|
insert
| 9 | 9 | 9 | 10 |
TLE
| |
p02269
|
C++
|
Memory Limit Exceeded
|
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define M 10465277
#define NIL (-1)
#define L 14
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;
else
return 0;
}
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main(int argc, char const *argv[]) {
char str[L], com[9];
int i, n, h;
std::cin >> n;
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
// printf("ins\n");
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define M 1046527
#define NIL (-1)
#define L 14
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;
else
return 0;
}
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main(int argc, char const *argv[]) {
char str[L], com[9];
int i, n, h;
std::cin >> n;
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
// printf("ins\n");
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
MLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
#define row 1001333 // 取一个比h2(k)大的质数
#define col 20
char H[row][col];
ll h1(ll key) { return key % row; }
ll h2(ll key) { return 1 + (key % (row - 1)); }
ll chtonum(char s) { // character to number
if (s == 'A')
return 1;
if (s == 'C')
return 2;
if (s == 'G')
return 3;
if (s == 'T')
return 4;
return 0;
}
ll get_key(char s[]) { // 生成key值
ll sum = 0, p = 1;
int len = strlen(s);
for (ll i = 0; i < len; i++) {
sum += p * chtonum(s[i]);
}
return sum;
}
void insert(char s[]) {
ll key, h;
key = get_key(s);
ll i = 0;
while (1) {
h = (h1(key) + i * h2(key)) % row; // 根据key值生成对应的位置
if (strcmp(H[h], s) == 0)
return; // 这个元素字典里已经有了
else if (strlen(H[h]) == 0) {
strcpy(H[h], s); // 如果该位置没有别的值,就把这个元素插进去
return;
}
i++; // 如果这个i对应的h的位置已经有元素了,那么继续寻找下一个i对应的位置
}
}
bool find(char s[]) {
ll key, h;
key = get_key(s);
ll i = 0;
while (1) {
h = (h1(key) + i * h2(key)) % row;
if (strcmp(H[h], s) == 0)
return true; // 如果找到了该元素
else if (strlen(H[h]) == 0)
return false;
i++;
}
return false;
}
int main() {
int n;
char c[20], s[20];
for (int i = 0; i < row; i++)
H[i][0] = '\0'; // 把数组初始化 方便比较
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> c >> s;
if (c[0] == 'i')
insert(s);
else {
if (find(s))
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
#define row 1001333 // 取一个比h2(k)大的质数
#define col 20
char H[row][col];
ll h1(ll key) { return key % row; }
ll h2(ll key) { return 1 + (key % (row - 1)); }
ll chtonum(char s) { // character to number
if (s == 'A')
return 1;
if (s == 'C')
return 2;
if (s == 'G')
return 3;
if (s == 'T')
return 4;
return 0;
}
ll get_key(char s[]) { // 生成key值
ll sum = 0, p = 1;
int len = strlen(s);
for (ll i = 0; i < len; i++) {
sum += p * chtonum(s[i]);
p *= 5;
}
return sum;
}
void insert(char s[]) {
ll key, h;
key = get_key(s);
ll i = 0;
while (1) {
h = (h1(key) + i * h2(key)) % row; // 根据key值生成对应的位置
if (strcmp(H[h], s) == 0)
return; // 这个元素字典里已经有了
else if (strlen(H[h]) == 0) {
strcpy(H[h], s); // 如果该位置没有别的值,就把这个元素插进去
return;
}
i++; // 如果这个i对应的h的位置已经有元素了,那么继续寻找下一个i对应的位置
}
}
bool find(char s[]) {
ll key, h;
key = get_key(s);
ll i = 0;
while (1) {
h = (h1(key) + i * h2(key)) % row;
if (strcmp(H[h], s) == 0)
return true; // 如果找到了该元素
else if (strlen(H[h]) == 0)
return false;
i++;
}
return false;
}
int main() {
int n;
char c[20], s[20];
for (int i = 0; i < row; i++)
H[i][0] = '\0'; // 把数组初始化 方便比较
scanf("%d", &n);
for (int i = 0; i < n; i++) {
cin >> c >> s;
if (c[0] == 'i')
insert(s);
else {
if (find(s))
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
return 0;
}
|
insert
| 47 | 47 | 47 | 49 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <stdio.h>
#include <string.h>
#define M 1000000
#define L 14
char H[M][L]; /* Hash Table */
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return (key % M - 1) + 1; }
// Hash function
int hash(int key, int i) { return (h1(key) + i * h2(key)); }
int find(char str[]) {
long long i = 0;
long long key = getKey(str);
while (true) {
long long j = hash(key, i);
if (strcmp(H[j], str) == 0)
return 1;
else if (strlen(H[j]) == 0)
return 0;
i++;
}
}
int insert(char str[]) {
long long i = 0;
long long key = getKey(str);
while (true) {
long long j = hash(key, i);
if (H[j][0] == '\0') {
strcpy(H[j], str);
return 1;
} else {
i++;
}
}
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define M 1000000
#define L 14
char H[M][L]; /* Hash Table */
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return (key % M - 1) + 1; }
// Hash function
int hash(int key, int i) { return (h1(key) + i * h2(key)) % M; }
int find(char str[]) {
long long i = 0;
long long key = getKey(str);
while (true) {
long long j = hash(key, i);
if (strcmp(H[j], str) == 0)
return 1;
else if (strlen(H[j]) == 0)
return 0;
i++;
}
}
int insert(char str[]) {
long long i = 0;
long long key = getKey(str);
while (true) {
long long j = hash(key, i);
if (H[j][0] == '\0') {
strcpy(H[j], str);
return 1;
} else {
i++;
}
}
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 32 | 33 | 32 | 33 |
0
| |
p02269
|
C++
|
Memory Limit Exceeded
|
#include <stdio.h>
#include <string.h>
#define M 10000000
#define L 14
char H[M][L]; /* Hash Table */
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define M 1000000
#define L 14
char H[M][L]; /* Hash Table */
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
MLE
| |
p02269
|
C++
|
Runtime Error
|
#include <stdio.h>
#include <string.h>
#define M 1046527
#define NIL (-1)
#define L 14
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;
else
return 0;
}
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 10;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
#define M 1046527
#define NIL (-1)
#define L 14
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;
else
return 0;
}
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 6;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
long long key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
replace
| 26 | 27 | 26 | 27 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
#define N 1000000
class Hash {
private:
list<string> *a;
unsigned long long getChar(char ch) {
switch (ch) {
case 'A':
return 1;
case 'C':
return 2;
case 'G':
return 3;
case 'T':
return 4;
default:
return 0;
}
}
unsigned long long getKey(string str) {
unsigned long long x = 0;
for (unsigned int i = 0; i < str.length(); i++) {
x += getChar(str[i]);
x *= 10;
}
return x % N;
}
public:
Hash() { a = new list<string>[N]; }
void insert(string str) { a[getKey(str)].push_back(str); }
bool find(string str) {
unsigned long long key = getKey(str);
list<string>::iterator itr = a[key].begin();
for (; itr != a[key].end(); itr++)
if (str == *itr)
return true;
return false;
}
};
int main() {
Hash H;
int n;
cin >> n;
string str;
for (int i = 0; i < n; i++) {
// cout << i << "\n";
cin >> str;
if (str[0] == 'i') {
cin >> str;
H.insert(str);
} else if (str[0] == 'f') {
cin >> str;
if (H.find(str))
cout << "yes\n";
else
cout << "no\n";
}
}
}
|
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
#define N 1000000
class Hash {
private:
list<string> *a;
unsigned long long getChar(char ch) {
switch (ch) {
case 'A':
return 1;
case 'C':
return 2;
case 'G':
return 3;
case 'T':
return 4;
default:
return 0;
}
}
unsigned long long getKey(string str) {
unsigned long long x = 0;
for (unsigned int i = 0; i < str.length(); i++) {
x += getChar(str[i]);
x *= 5;
}
return x % N;
}
public:
Hash() { a = new list<string>[N]; }
void insert(string str) { a[getKey(str)].push_back(str); }
bool find(string str) {
unsigned long long key = getKey(str);
list<string>::iterator itr = a[key].begin();
for (; itr != a[key].end(); itr++)
if (str == *itr)
return true;
return false;
}
};
int main() {
Hash H;
int n;
cin >> n;
string str;
for (int i = 0; i < n; i++) {
// cout << i << "\n";
cin >> str;
if (str[0] == 'i') {
cin >> str;
H.insert(str);
} else if (str[0] == 'f') {
cin >> str;
if (H.find(str))
cout << "yes\n";
else
cout << "no\n";
}
}
}
|
replace
| 34 | 35 | 34 | 35 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <stdio.h>
#include <string.h>
int Hash[244140];
char s[13];
int getChar(char ch) {
if (ch == 'A') {
return 1;
} else if (ch == 'C') {
return 2;
} else if (ch == 'G') {
return 3;
}
return 4;
}
int getKey() {
int sum = 0, p = 1;
for (int i = 0; i < strlen(s); i++) {
sum += p * (getChar(s[i]));
p *= 5;
}
return sum;
}
int main() {
int n;
char com[7];
scanf("%d", &n);
while (n--) {
scanf("%s %s", com, s);
if (com[0] == 'i') {
Hash[getKey()] = 1;
// printf("%d\n",getKey());
} else {
if (Hash[getKey()]) {
puts("yes");
} else {
puts("no");
}
}
}
return 0;
}
|
#include <stdio.h>
#include <string.h>
int Hash[244140625];
char s[13];
int getChar(char ch) {
if (ch == 'A') {
return 1;
} else if (ch == 'C') {
return 2;
} else if (ch == 'G') {
return 3;
}
return 4;
}
int getKey() {
int sum = 0, p = 1;
for (int i = 0; i < strlen(s); i++) {
sum += p * (getChar(s[i]));
p *= 5;
}
return sum;
}
int main() {
int n;
char com[7];
scanf("%d", &n);
while (n--) {
scanf("%s %s", com, s);
if (com[0] == 'i') {
Hash[getKey()] = 1;
// printf("%d\n",getKey());
} else {
if (Hash[getKey()]) {
puts("yes");
} else {
puts("no");
}
}
}
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p02269
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define M 10000019 /* your task*/
#define L 14
char H[M][L]; /* Hash Table */
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + key % (M - 1); }
int h(int key, int i) { return (h1(key) + i * h2(key)) % M; }
int find(char str[]) {
long long key = getKey(str);
for (int i = 0;; i++) {
int idx = h(key, i);
if (H[idx][0] == '\0')
return false;
if (strcmp(str, H[idx]) == 0)
return true;
}
}
int insert(char str[]) {
long long key = getKey(str);
int idx = 0;
for (int i = 0;; i++) {
idx = h(key, i);
if (H[idx][0] == '\0')
break;
}
strcpy(H[idx], str);
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define M 1000033 /* your task*/
#define L 14
char H[M][L]; /* Hash Table */
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + key % (M - 1); }
int h(int key, int i) { return (h1(key) + i * h2(key)) % M; }
int find(char str[]) {
long long key = getKey(str);
for (int i = 0;; i++) {
int idx = h(key, i);
if (H[idx][0] == '\0')
return false;
if (strcmp(str, H[idx]) == 0)
return true;
}
}
int insert(char str[]) {
long long key = getKey(str);
int idx = 0;
for (int i = 0;; i++) {
idx = h(key, i);
if (H[idx][0] == '\0')
break;
}
strcpy(H[idx], str);
}
int main() {
int i, n, h;
char str[L], com[9];
for (i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
MLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
int main(void) {
std::ios_base::sync_with_stdio(false);
int n;
std::cin >> n;
std::set<std::string> DICTIONARY;
std::string COMMAND;
std::string WORD;
for (int i = 0; i < n; ++i) {
std::cin >> COMMAND >> WORD;
if (COMMAND == "insert") {
DICTIONARY.insert(WORD);
} else if (COMMAND == "find") {
if (std::find(DICTIONARY.begin(), DICTIONARY.end(), WORD) !=
DICTIONARY.end()) {
std::cout << "yes" << std::endl;
} else {
std::cout << "no" << std::endl;
}
}
}
// system("pause");
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
int main(void) {
std::ios_base::sync_with_stdio(false);
int n;
std::cin >> n;
std::set<std::string> DICTIONARY;
std::string COMMAND;
std::string WORD;
for (int i = 0; i < n; ++i) {
std::cin >> COMMAND >> WORD;
if (COMMAND == "insert") {
DICTIONARY.insert(WORD);
} else if (COMMAND == "find") {
// if (std::find(DICTIONARY.begin(), DICTIONARY.end(), WORD) !=
// DICTIONARY.end())
if (DICTIONARY.find(WORD) != DICTIONARY.end()) {
std::cout << "yes" << std::endl;
} else {
std::cout << "no" << std::endl;
}
}
}
// system("pause");
return 0;
}
|
replace
| 17 | 20 | 17 | 20 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define M 1050011
#define L 14
char H[M][L];
long long h1(long long k) { return k % M; }
long long h2(long long k) { return 1 + (k % (M - 1)); }
long long h(long long k, long long i) { return (h1(k) + i * h2(k)) % M; }
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int find(char str[]) {
long long key, i, id;
key = getKey(str);
i = 0;
while (true) {
id = h(key, i);
if (strcmp(H[id], str) == 0)
return 1;
else if (strlen(H[id]) == 0)
return 0;
i++;
}
return 0;
}
int insert(char str[]) {
long long key, i, id;
key = getKey(str);
i = 0;
while (true) {
id = h(key, i);
if (strcmp(H[id], str) == 0)
return 1;
else if (strlen(H[id]) == 0) {
strcpy(H[id], str);
return 0;
}
}
return 0;
}
int main() {
int n;
char str[L], command[10];
for (int i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %s", command, str);
if (command[0] == 'i')
insert(str);
else {
if (find(str))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define M 1050011
#define L 14
char H[M][L];
long long h1(long long k) { return k % M; }
long long h2(long long k) { return 1 + (k % (M - 1)); }
long long h(long long k, long long i) { return (h1(k) + i * h2(k)) % M; }
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;
}
/* convert a string into an integer value */
long long getKey(char str[]) {
long long sum = 0, p = 1, i;
for (i = 0; i < strlen(str); i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int find(char str[]) {
long long key, i, id;
key = getKey(str);
i = 0;
while (true) {
id = h(key, i);
if (strcmp(H[id], str) == 0)
return 1;
else if (strlen(H[id]) == 0)
return 0;
i++;
}
return 0;
}
int insert(char str[]) {
long long key, i, id;
key = getKey(str);
i = 0;
while (true) {
id = h(key, i);
if (strcmp(H[id], str) == 0)
return 1;
else if (strlen(H[id]) == 0) {
strcpy(H[id], str);
return 0;
}
i++;
}
return 0;
}
int main() {
int n;
char str[L], command[10];
for (int i = 0; i < M; i++)
H[i][0] = '\0';
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %s", command, str);
if (command[0] == 'i')
insert(str);
else {
if (find(str))
printf("yes\n");
else
printf("no\n");
}
}
return 0;
}
|
insert
| 69 | 69 | 69 | 70 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#define y0 qvya13579
#define y1 qvyb24680
#define j0 qvja13579
#define j1 qvjb24680
#define next qvne13579xt
#define prev qvpr13579ev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS \
cin.tie(0); \
ios::sync_with_stdio(false)
#define M_P make_pair
#define PU_B push_back
#define PU_F push_front
#define PO_B pop_back
#define PO_F pop_front
#define U_B upper_bound
#define L_B lower_bound
#define B_S binary_search
#define PR_Q priority_queue
#define FIR first
#define SEC second
#if __cplusplus < 201103L
#define stoi(argument_string) atoi((argument_string).c_str())
#endif
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP_R(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define FOR(i, m, n) for (int i = ((int)(m)); i < (int)(n); ++i)
#define FOR_R(i, m, n) for (int i = ((int)(m)-1); i >= (int)(n); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SIZ(x) ((int)(x).size())
#define COUT(x) cout << (x) << endl
#define CIN(x) cin >> (x)
#define CIN2(x, y) cin >> (x) >> (y)
#define CIN3(x, y, z) cin >> (x) >> (y) >> (z)
#define CIN4(x, y, z, w) cin >> (x) >> (y) >> (z) >> (w)
#define SCAND(x) scanf("%d", &(x))
#define SCAND2(x, y) scanf("%d%d", &(x), &(y))
#define SCAND3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
#define SCAND4(x, y, z, w) scanf("%d%d%d%d", &(x), &(y), &(z), &(w))
#define SCANLLD(x) scanf("%lld", &(x))
#define SCANLLD2(x, y) scanf("%lld%lld", &(x), &(y))
#define SCANLLD3(x, y, z) scanf("%lld%lld%lld", &(x), &(y), &(z))
#define SCANLLD4(x, y, z, w) scanf("%lld%lld%lld%lld", &(x), &(y), &(z), &(w))
#define PRINTD(x) printf("%d\n", (x))
#define PRINTLLD(x) printf("%lld\n", (x))
typedef long long int lli;
using namespace std;
bool compare_by_2nd(pair<int, int> a, pair<int, int> b) {
if (a.second != b.second) {
return a.second < b.second;
} else {
return a.first < b.first;
}
}
int ctoi(char c) {
if (c >= '0' and c <= '9') {
return (int)(c - '0');
}
return -1;
}
int alphabet_pos(char c) {
if (c >= 'a' and c <= 'z') {
return (int)(c - 'a');
}
return -1;
}
int alphabet_pos_capital(char c) {
if (c >= 'A' and c <= 'Z') {
return (int)(c - 'A');
}
return -1;
}
vector<string> split(string str, char ch) {
int first = 0;
int last = str.find_first_of(ch);
if (last == string::npos) {
last = SIZ(str);
}
vector<string> result;
while (first < SIZ(str)) {
string Ssubstr(str, first, last - first);
result.push_back(Ssubstr);
first = last + 1;
last = str.find_first_of(ch, first);
if (last == string::npos) {
last = SIZ(str);
}
}
return result;
}
int gcd(int a, int b) // assuming a,b >= 1
{
if (a < b) {
return gcd(b, a);
}
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
return a * b / gcd(a, b);
}
/*------------------ the end of the template -----------------------*/
#define M 1046527
int getchar(char ch) {
switch (ch) {
case 'A':
return 1;
break;
case 'C':
return 2;
break;
case 'G':
return 3;
break;
case 'T':
return 4;
break;
default:
return 0;
}
}
lli getkey(string str) {
lli sm = 0;
lli p = 1;
REP(i, SIZ(str)) {
sm += (alphabet_pos_capital(str[i]) + 1) * p;
p *= 3;
}
return sm;
}
int indgen(string str, lli i) {
lli temp = getkey(str);
return ((temp % 1919) + i * ((temp % 541) + 1)) % M;
}
int insert(string str, vector<string> &v) {
lli i = 0;
int h;
for (i = 0; i < M; ++i) {
h = indgen(str, i);
if (v[h] == str) {
return 1;
} else if (SIZ(v[h]) == 0) {
v[h] = str;
return 0;
}
}
}
int find(string str, vector<string> &v) {
lli i = 0;
int h;
for (i = 0; i < M; ++i) {
h = indgen(str, i);
if (v[h] == str) {
return 1;
} else if (SIZ(v[h]) == 0) {
return 0;
}
}
}
int main() {
IOS; /* making cin faster */
vector<string> v(M);
int n;
CIN(n);
string com, st;
REP(i, n) {
CIN2(com, st);
if (com == "insert") {
insert(st, v);
} else {
if (find(st, v)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
}
|
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
#define y0 qvya13579
#define y1 qvyb24680
#define j0 qvja13579
#define j1 qvjb24680
#define next qvne13579xt
#define prev qvpr13579ev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS \
cin.tie(0); \
ios::sync_with_stdio(false)
#define M_P make_pair
#define PU_B push_back
#define PU_F push_front
#define PO_B pop_back
#define PO_F pop_front
#define U_B upper_bound
#define L_B lower_bound
#define B_S binary_search
#define PR_Q priority_queue
#define FIR first
#define SEC second
#if __cplusplus < 201103L
#define stoi(argument_string) atoi((argument_string).c_str())
#endif
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP_R(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define FOR(i, m, n) for (int i = ((int)(m)); i < (int)(n); ++i)
#define FOR_R(i, m, n) for (int i = ((int)(m)-1); i >= (int)(n); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SIZ(x) ((int)(x).size())
#define COUT(x) cout << (x) << endl
#define CIN(x) cin >> (x)
#define CIN2(x, y) cin >> (x) >> (y)
#define CIN3(x, y, z) cin >> (x) >> (y) >> (z)
#define CIN4(x, y, z, w) cin >> (x) >> (y) >> (z) >> (w)
#define SCAND(x) scanf("%d", &(x))
#define SCAND2(x, y) scanf("%d%d", &(x), &(y))
#define SCAND3(x, y, z) scanf("%d%d%d", &(x), &(y), &(z))
#define SCAND4(x, y, z, w) scanf("%d%d%d%d", &(x), &(y), &(z), &(w))
#define SCANLLD(x) scanf("%lld", &(x))
#define SCANLLD2(x, y) scanf("%lld%lld", &(x), &(y))
#define SCANLLD3(x, y, z) scanf("%lld%lld%lld", &(x), &(y), &(z))
#define SCANLLD4(x, y, z, w) scanf("%lld%lld%lld%lld", &(x), &(y), &(z), &(w))
#define PRINTD(x) printf("%d\n", (x))
#define PRINTLLD(x) printf("%lld\n", (x))
typedef long long int lli;
using namespace std;
bool compare_by_2nd(pair<int, int> a, pair<int, int> b) {
if (a.second != b.second) {
return a.second < b.second;
} else {
return a.first < b.first;
}
}
int ctoi(char c) {
if (c >= '0' and c <= '9') {
return (int)(c - '0');
}
return -1;
}
int alphabet_pos(char c) {
if (c >= 'a' and c <= 'z') {
return (int)(c - 'a');
}
return -1;
}
int alphabet_pos_capital(char c) {
if (c >= 'A' and c <= 'Z') {
return (int)(c - 'A');
}
return -1;
}
vector<string> split(string str, char ch) {
int first = 0;
int last = str.find_first_of(ch);
if (last == string::npos) {
last = SIZ(str);
}
vector<string> result;
while (first < SIZ(str)) {
string Ssubstr(str, first, last - first);
result.push_back(Ssubstr);
first = last + 1;
last = str.find_first_of(ch, first);
if (last == string::npos) {
last = SIZ(str);
}
}
return result;
}
int gcd(int a, int b) // assuming a,b >= 1
{
if (a < b) {
return gcd(b, a);
}
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
int lcm(int a, int b) // assuming a,b >= 1
{
return a * b / gcd(a, b);
}
/*------------------ the end of the template -----------------------*/
#define M 1046527
int getchar(char ch) {
switch (ch) {
case 'A':
return 1;
break;
case 'C':
return 2;
break;
case 'G':
return 3;
break;
case 'T':
return 4;
break;
default:
return 0;
}
}
lli getkey(string str) {
lli sm = 0;
lli p = 1;
REP(i, SIZ(str)) {
sm += (alphabet_pos_capital(str[i]) + 1) * p;
p *= 3;
}
return sm;
}
int indgen(string str, lli i) {
lli temp = getkey(str);
return ((temp % M) + i * ((temp % (M - 1)) + 1)) % M;
}
int insert(string str, vector<string> &v) {
lli i = 0;
int h;
for (i = 0; i < M; ++i) {
h = indgen(str, i);
if (v[h] == str) {
return 1;
} else if (SIZ(v[h]) == 0) {
v[h] = str;
return 0;
}
}
}
int find(string str, vector<string> &v) {
lli i = 0;
int h;
for (i = 0; i < M; ++i) {
h = indgen(str, i);
if (v[h] == str) {
return 1;
} else if (SIZ(v[h]) == 0) {
return 0;
}
}
}
int main() {
IOS; /* making cin faster */
vector<string> v(M);
int n;
CIN(n);
string com, st;
REP(i, n) {
CIN2(com, st);
if (com == "insert") {
insert(st, v);
} else {
if (find(st, v)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
}
|
replace
| 245 | 246 | 245 | 246 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long lli;
const int M = 5000001;
const int P = 32;
lli C[128];
lli X[M];
lli convert(const char s[]) {
lli j = 0;
for (lli i = 0; s[i] != '\0'; ++i) {
j |= C[s[i]] << (i * 3LL);
}
return j;
}
void insert(const char s[]) {
int x = convert(s);
int p = x % M;
while (X[p] != -1LL)
p = (p + P) % M;
X[p] = x;
}
bool find(const char s[]) {
int x = convert(s);
int p = x % M;
while (X[p] != -1LL) {
if (X[p] == x)
return true;
p = (p + P) % M;
}
return false;
}
int main() {
int n;
char s[100];
C['A'] = 1LL;
C['C'] = 2LL;
C['G'] = 3LL;
C['T'] = 4LL;
fill(X, X + M, -1LL);
scanf("%d", &n);
while (n--) {
scanf("%s", s);
if (s[0] == 'f') {
scanf("%s", s);
if (find(s))
printf("yes\n");
else
printf("no\n");
} else {
scanf("%s", s);
insert(s);
}
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long lli;
const int M = 5000001;
const int P = M / 10;
lli C[128];
lli X[M];
lli convert(const char s[]) {
lli j = 0;
for (lli i = 0; s[i] != '\0'; ++i) {
j |= C[s[i]] << (i * 3LL);
}
return j;
}
void insert(const char s[]) {
int x = convert(s);
int p = x % M;
while (X[p] != -1LL)
p = (p + P) % M;
X[p] = x;
}
bool find(const char s[]) {
int x = convert(s);
int p = x % M;
while (X[p] != -1LL) {
if (X[p] == x)
return true;
p = (p + P) % M;
}
return false;
}
int main() {
int n;
char s[100];
C['A'] = 1LL;
C['C'] = 2LL;
C['G'] = 3LL;
C['T'] = 4LL;
fill(X, X + M, -1LL);
scanf("%d", &n);
while (n--) {
scanf("%s", s);
if (s[0] == 'f') {
scanf("%s", s);
if (find(s))
printf("yes\n");
else
printf("no\n");
} else {
scanf("%s", s);
insert(s);
}
}
return 0;
}
|
replace
| 10 | 11 | 10 | 11 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef unsigned int uint;
const uint M = 6000011u;
const uint P = 2u;
uint Five[13];
uint C[128];
uint X[M];
uint convert(const char s[]) {
uint j = 0;
for (uint i = 0u; s[i] != '\0'; ++i) {
j += C[s[i]] * Five[i];
}
return j;
}
void insert(const char s[]) {
uint x = convert(s);
uint p = x % M;
while (X[p] != UINT_MAX)
p = (p + P) % M;
X[p] = x;
}
bool find(const char s[]) {
uint x = convert(s);
uint p = x % M;
while (X[p] != UINT_MAX) {
if (X[p] == x)
return true;
p = (p + P) % M;
}
return false;
}
int main() {
int n;
char s[100];
C['A'] = 1u;
C['C'] = 2u;
C['G'] = 3u;
C['T'] = 4u;
Five[0] = 1u;
for (int i = 1; i < 13; ++i)
Five[i] = Five[i - 1] * 5u;
fill(X, X + M, UINT_MAX);
scanf("%d", &n);
while (n--) {
scanf("%s", s);
if (s[0] == 'f') {
scanf("%s", s);
if (find(s))
printf("yes\n");
else
printf("no\n");
} else {
scanf("%s", s);
insert(s);
}
}
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef unsigned int uint;
const uint M = 6000011u;
const uint P = M / 10u + 1u;
uint Five[13];
uint C[128];
uint X[M];
uint convert(const char s[]) {
uint j = 0;
for (uint i = 0u; s[i] != '\0'; ++i) {
j += C[s[i]] * Five[i];
}
return j;
}
void insert(const char s[]) {
uint x = convert(s);
uint p = x % M;
while (X[p] != UINT_MAX)
p = (p + P) % M;
X[p] = x;
}
bool find(const char s[]) {
uint x = convert(s);
uint p = x % M;
while (X[p] != UINT_MAX) {
if (X[p] == x)
return true;
p = (p + P) % M;
}
return false;
}
int main() {
int n;
char s[100];
C['A'] = 1u;
C['C'] = 2u;
C['G'] = 3u;
C['T'] = 4u;
Five[0] = 1u;
for (int i = 1; i < 13; ++i)
Five[i] = Five[i - 1] * 5u;
fill(X, X + M, UINT_MAX);
scanf("%d", &n);
while (n--) {
scanf("%s", s);
if (s[0] == 'f') {
scanf("%s", s);
if (find(s))
printf("yes\n");
else
printf("no\n");
} else {
scanf("%s", s);
insert(s);
}
}
return 0;
}
|
replace
| 11 | 12 | 11 | 12 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
class dictionary {
private:
string *hashtable;
long long table_size;
int el_num;
long long hash1(string);
long long hash2(string);
long long str_n(string);
public:
dictionary(int n);
void insert(string);
bool find(string);
};
inline dictionary::dictionary(int n) {
hashtable = new string[n];
if (!hashtable) {
cout << "Allocation Error" << endl;
abort();
}
table_size = n;
el_num = 0;
}
inline long long dictionary::hash1(string str) {
return str_n(str) % table_size;
}
inline long long dictionary::hash2(string str) {
return 1 + (str_n(str) % (table_size - 1));
}
inline long long dictionary::str_n(string str) {
long long str_n = 0;
for (unsigned int i = 0; i < str.size(); i++) {
str_n = str_n * 5 +
(long long)str[i]; // str_n += (int)str[i]
// ?????????????????????????????????????????£???
}
return str_n;
}
inline void dictionary::insert(string str) {
/*
if( el_num >= table_size ){
cout<<"????????\????????????????????????"<<endl;
abort();
}
long long hash_v;
int coltimes=0;
do{
hash_v = ( hash1(str) + hash2(str)*coltimes )%table_size ;
// printf("I ( hash1, hash2, hash )(coltimes) = ( %d, %d,
%d)(%d)\n", hash1(str), hash2(str), hash_v, coltimes ); }while( (hashtable[
hash_v ].size() && hashtable[ hash_v ]!=str), coltimes++ );
hashtable[ hash_v ]=str;
*/
long long hash_v;
for (int i = 0;; i++) {
hash_v = (hash1(str) + hash2(str) * i) % table_size;
if (hashtable[hash_v] == str) {
return;
} else if (!hashtable[hash_v].size()) {
hashtable[hash_v] = str;
return;
}
}
}
inline bool dictionary::find(string str) {
long long hash_v;
for (int i = 0;; i++) {
hash_v = hash1(str) + hash2(str) * i;
if (hashtable[hash_v] == str) {
return true;
} else if (!hashtable[hash_v].size()) {
return false;
}
}
}
int main() {
int n;
scanf("%d", &n);
char command[7], str[13];
dictionary dic(1046527);
for (int i = 0; i < n; i++) {
scanf("%s %s", command, str);
if (!strcmp(command, "insert")) {
dic.insert(str);
} else if (!strcmp(command, "find")) {
cout << (dic.find(str) ? "yes" : "no") << endl;
}
}
}
|
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
class dictionary {
private:
string *hashtable;
long long table_size;
int el_num;
long long hash1(string);
long long hash2(string);
long long str_n(string);
public:
dictionary(int n);
void insert(string);
bool find(string);
};
inline dictionary::dictionary(int n) {
hashtable = new string[n];
if (!hashtable) {
cout << "Allocation Error" << endl;
abort();
}
table_size = n;
el_num = 0;
}
inline long long dictionary::hash1(string str) {
return str_n(str) % table_size;
}
inline long long dictionary::hash2(string str) {
return 1 + (str_n(str) % (table_size - 1));
}
inline long long dictionary::str_n(string str) {
long long str_n = 0;
for (unsigned int i = 0; i < str.size(); i++) {
str_n = str_n * 5 +
(long long)str[i]; // str_n += (int)str[i]
// ?????????????????????????????????????????£???
}
return str_n;
}
inline void dictionary::insert(string str) {
/*
if( el_num >= table_size ){
cout<<"????????\????????????????????????"<<endl;
abort();
}
long long hash_v;
int coltimes=0;
do{
hash_v = ( hash1(str) + hash2(str)*coltimes )%table_size ;
// printf("I ( hash1, hash2, hash )(coltimes) = ( %d, %d,
%d)(%d)\n", hash1(str), hash2(str), hash_v, coltimes ); }while( (hashtable[
hash_v ].size() && hashtable[ hash_v ]!=str), coltimes++ );
hashtable[ hash_v ]=str;
*/
long long hash_v;
for (int i = 0;; i++) {
hash_v = (hash1(str) + hash2(str) * i) % table_size;
if (hashtable[hash_v] == str) {
return;
} else if (!hashtable[hash_v].size()) {
hashtable[hash_v] = str;
return;
}
}
}
inline bool dictionary::find(string str) {
long long hash_v;
for (int i = 0;; i++) {
hash_v = (hash1(str) + hash2(str) * i) % table_size;
if (hashtable[hash_v] == str) {
return true;
} else if (!hashtable[hash_v].size()) {
return false;
}
}
}
int main() {
int n;
scanf("%d", &n);
char command[7], str[13];
dictionary dic(1046527);
for (int i = 0; i < n; i++) {
scanf("%s %s", command, str);
if (!strcmp(command, "insert")) {
dic.insert(str);
} else if (!strcmp(command, "find")) {
cout << (dic.find(str) ? "yes" : "no") << endl;
}
}
}
|
replace
| 82 | 83 | 82 | 83 |
0
| |
p02269
|
C++
|
Runtime Error
|
#include <iostream>
#include <list>
#include <stdio.h>
#include <string>
using namespace std;
#define N 22369620
#define X 25
struct hush {
list<int> a;
};
int main(void) {
int n, sum = 0, x, f[1000000] = {0}, cou = 0;
char str[7], acgt[13];
hush H[N / X];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
sum = 0;
scanf("%s", str);
scanf("%s", acgt);
for (int i = 0, k = 1; acgt[i] != '\0' && i < 12; i++, k *= 4) {
switch (acgt[i]) {
case 'A':
x = 1;
break;
case 'C':
x = 2;
break;
case 'G':
x = 3;
break;
case 'T':
x = 4;
break;
}
sum += x * k;
}
if (str[0] == 'i') {
H[sum / X].a.push_back(sum % X);
} else {
list<int>::iterator p = H[sum / X].a.begin();
for (; p != H[sum / X].a.end(); ++p) {
if ((sum % X) == *p) {
f[cou] = 1;
}
}
cou++;
}
}
for (int i = 0; i < cou; i++) {
if (f[i])
printf("yes\n");
else
printf("no\n");
}
}
|
#include <iostream>
#include <list>
#include <stdio.h>
#include <string>
using namespace std;
#define N 22369620
#define X 50
struct hush {
list<int> a;
};
int main(void) {
int n, sum = 0, x, f[1000000] = {0}, cou = 0;
char str[7], acgt[13];
hush H[N / X];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
sum = 0;
scanf("%s", str);
scanf("%s", acgt);
for (int i = 0, k = 1; acgt[i] != '\0' && i < 12; i++, k *= 4) {
switch (acgt[i]) {
case 'A':
x = 1;
break;
case 'C':
x = 2;
break;
case 'G':
x = 3;
break;
case 'T':
x = 4;
break;
}
sum += x * k;
}
if (str[0] == 'i') {
H[sum / X].a.push_back(sum % X);
} else {
list<int>::iterator p = H[sum / X].a.begin();
for (; p != H[sum / X].a.end(); ++p) {
if ((sum % X) == *p) {
f[cou] = 1;
}
}
cou++;
}
}
for (int i = 0; i < cou; i++) {
if (f[i])
printf("yes\n");
else
printf("no\n");
}
}
|
replace
| 6 | 7 | 6 | 7 |
-11
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
// std::ios_base::sync_with_stdio(false);
set<string> st;
int n;
cin >> n;
while (n--) {
string BUFF, c;
cin >> BUFF >> c;
if (BUFF == "insert")
st.insert(c);
else
cout << (st.find(c) != st.end() ? "yes" : "no") << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
set<string> st;
int n;
cin >> n;
while (n--) {
string BUFF, c;
cin >> BUFF >> c;
if (BUFF == "insert")
st.insert(c);
else
cout << (st.find(c) != st.end() ? "yes" : "no") << endl;
}
}
|
replace
| 7 | 8 | 7 | 8 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
const long N = 1046527;
char str[N][13];
long n;
int getInt(char ch) {
switch (ch) {
case 'A':
return 1;
case 'T':
return 2;
case 'G':
return 3;
case 'C':
return 4;
}
return 0;
}
long long getKey(char *tmp) {
long long sum = 0, p = 1;
for (int i = 0; i < strlen(tmp); ++i) {
sum += p * getInt(tmp[i]);
p *= 5;
}
return sum;
}
int main() {
scanf("%ld", &n);
while (n--) {
char ch[13];
scanf("%s", ch);
if (strcmp(ch, "insert") == 0) {
scanf("%s", ch);
long long tmp = getKey(ch);
strcpy(str[tmp], ch);
} else if (strcmp(ch, "find") == 0) {
scanf("%s", ch);
long long tmp = getKey(ch);
if (strcmp(str[tmp], ch) == 0)
cout << "yes\n";
else
cout << "no\n";
}
}
}
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
const long N = 16777216;
char str[N][13];
long n;
int getInt(char ch) {
switch (ch) {
case 'A':
return 1;
case 'T':
return 2;
case 'G':
return 3;
case 'C':
return 4;
}
return 0;
}
long long getKey(char *tmp) {
long long sum = 0, p = 1;
for (int i = 0; i < strlen(tmp); ++i) {
sum += p * getInt(tmp[i]);
p *= 5;
}
return sum;
}
int main() {
scanf("%ld", &n);
while (n--) {
char ch[13];
scanf("%s", ch);
if (strcmp(ch, "insert") == 0) {
scanf("%s", ch);
long long tmp = getKey(ch);
strcpy(str[tmp], ch);
} else if (strcmp(ch, "find") == 0) {
scanf("%s", ch);
long long tmp = getKey(ch);
if (strcmp(str[tmp], ch) == 0)
cout << "yes\n";
else
cout << "no\n";
}
}
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
int n, i;
cin >> n;
string command, str;
set<string> S;
for (i = 0; i < n; i++) {
cin >> command >> str;
if (command == "insert") {
S.insert(str);
} else {
if (S.find(str) == S.end()) {
cout << "no" << endl;
} else {
cout << "yes" << endl;
}
}
}
return 0;
}
|
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, i;
cin >> n;
string command, str;
set<string> S;
for (i = 0; i < n; i++) {
cin >> command >> str;
if (command == "insert") {
S.insert(str);
} else {
if (S.find(str) == S.end()) {
cout << "no" << endl;
} else {
cout << "yes" << endl;
}
}
}
return 0;
}
|
insert
| 6 | 6 | 6 | 7 |
TLE
| |
p02269
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <time.h>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
int dic[1000000];
ull pow(ull x, ull n) {
ull res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
int dic_op(char str[14], int &key) {
int j;
int f = 1;
int g = 0;
for (j = 0; j < 10; j++) {
if (str[j] == 'A')
g += f * 1;
else if (str[j] == 'C')
g += f * 2;
else if (str[j] == 'G')
g += f * 3;
else if (str[j] == 'T')
g += f * 4;
else
break;
f *= 5;
}
key = 0;
if (j == 10) {
f = 1;
for (; j < 10; j++) {
if (str[j] == 'A')
key += f * 1;
else if (str[j] == 'C')
key += f * 2;
else if (str[j] == 'G')
key += f * 3;
else if (str[j] == 'T')
key += f * 4;
else
break;
f *= 5;
}
}
return g;
}
int main() {
int i, j, k, l;
long n;
long ans = 0;
char opstr[7];
char str[13];
int key;
int a = 1;
cin >> n;
for (i = 0; i < n; i++) {
scanf("%s %s", opstr, str);
if (opstr[0] == 'i') {
int tmp = dic_op(str, key);
if ((dic[tmp] >> key) % 2 == 0) {
dic[tmp] += 1 << key;
}
} else if (opstr[0] == 'f') {
int tmp = dic_op(str, key);
/*
printf("tmp = %d\n",tmp);
printf("key = %d\n",key);
printf("dic[tmp] = %d\n",dic[tmp]);
*/
if ((dic[tmp] >> key) % 2 == 1) {
puts("yes");
} else {
puts("no");
}
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits.h>
#include <time.h>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
int dic[20000000];
ull pow(ull x, ull n) {
ull res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
int dic_op(char str[14], int &key) {
int j;
int f = 1;
int g = 0;
for (j = 0; j < 10; j++) {
if (str[j] == 'A')
g += f * 1;
else if (str[j] == 'C')
g += f * 2;
else if (str[j] == 'G')
g += f * 3;
else if (str[j] == 'T')
g += f * 4;
else
break;
f *= 5;
}
key = 0;
if (j == 10) {
f = 1;
for (; j < 10; j++) {
if (str[j] == 'A')
key += f * 1;
else if (str[j] == 'C')
key += f * 2;
else if (str[j] == 'G')
key += f * 3;
else if (str[j] == 'T')
key += f * 4;
else
break;
f *= 5;
}
}
return g;
}
int main() {
int i, j, k, l;
long n;
long ans = 0;
char opstr[7];
char str[13];
int key;
int a = 1;
cin >> n;
for (i = 0; i < n; i++) {
scanf("%s %s", opstr, str);
if (opstr[0] == 'i') {
int tmp = dic_op(str, key);
if ((dic[tmp] >> key) % 2 == 0) {
dic[tmp] += 1 << key;
}
} else if (opstr[0] == 'f') {
int tmp = dic_op(str, key);
/*
printf("tmp = %d\n",tmp);
printf("key = %d\n",key);
printf("dic[tmp] = %d\n",dic[tmp]);
*/
if ((dic[tmp] >> key) % 2 == 1) {
puts("yes");
} else {
puts("no");
}
}
}
return 0;
}
|
replace
| 19 | 20 | 19 | 20 |
0
| |
p02269
|
C++
|
Runtime Error
|
#include <cstdio>
#include <iostream>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
ull pow(ull x, ull n) {
ull res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
int dic_op(char str[14]) {
int j;
long long f = 1;
long long g = 0;
for (j = 0;; j++) {
if (str[j] == 'A')
g += f * 1;
else if (str[j] == 'C')
g += f * 2;
else if (str[j] == 'G')
g += f * 3;
else if (str[j] == 'T')
g += f * 4;
else
break;
f *= 5;
}
return g;
}
int main() {
int i, j, k, l;
int n;
long ans = 0;
static char dic[7000000];
char opstr[7];
char str[13];
cin >> n;
for (i = 0; i < n; i++) {
scanf("%s %s", opstr, str);
if (opstr[0] == 'i') {
dic[dic_op(str)] = 1;
} else if (opstr[0] == 'f') {
if (dic[dic_op(str)] == 1)
puts("yes");
else
puts("no");
j++;
}
}
return 0;
}
|
#include <cstdio>
#include <iostream>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
ull pow(ull x, ull n) {
ull res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
int dic_op(char str[14]) {
int j;
long long f = 1;
long long g = 0;
for (j = 0;; j++) {
if (str[j] == 'A')
g += f * 1;
else if (str[j] == 'C')
g += f * 2;
else if (str[j] == 'G')
g += f * 3;
else if (str[j] == 'T')
g += f * 4;
else
break;
f *= 5;
}
return g;
}
int main() {
int i, j, k, l;
int n;
long ans = 0;
static char dic[10000000];
char opstr[7];
char str[13];
cin >> n;
for (i = 0; i < n; i++) {
scanf("%s %s", opstr, str);
if (opstr[0] == 'i') {
dic[dic_op(str)] = 1;
} else if (opstr[0] == 'f') {
if (dic[dic_op(str)] == 1)
puts("yes");
else
puts("no");
j++;
}
}
return 0;
}
|
replace
| 48 | 49 | 48 | 49 |
0
| |
p02269
|
C++
|
Runtime Error
|
#include <cstdio>
#include <iostream>
#include <limits.h>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
ull pow(ull x, ull n) {
ull res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
int dic_op(char str[14], int &key) {
int j;
int f = 1;
int g = 0;
for (j = 0; j < 10; j++) {
if (str[j] == 'A')
g += f * 1;
else if (str[j] == 'C')
g += f * 2;
else if (str[j] == 'G')
g += f * 3;
else if (str[j] == 'T')
g += f * 4;
else
break;
f *= 5;
}
key = 0;
if (j == 10) {
f = 1;
for (; j < 10; j++) {
if (str[j] == 'A')
key += f * 1;
else if (str[j] == 'C')
key += f * 2;
else if (str[j] == 'G')
key += f * 3;
else if (str[j] == 'T')
key += f * 4;
else
break;
f *= 5;
}
}
return g;
}
int main() {
int i;
int dic[10000000];
int n;
char opstr[7];
char str[13];
int key;
cin >> n;
for (i = 0; i < n; i++) {
scanf("%s %s", opstr, str);
if (opstr[0] == 'i') {
int tmp = dic_op(str, key);
if ((dic[tmp] >> key) % 2 == 0) {
dic[tmp] += 1 << key;
}
} else if (opstr[0] == 'f') {
int tmp = dic_op(str, key);
/*
printf("tmp = %d\n",tmp);
printf("key = %d\n",key);
printf("dic[tmp] = %d\n",dic[tmp]);
*/
if ((dic[tmp] >> key) % 2 == 1) {
puts("yes");
} else {
puts("no");
}
}
}
return 0;
}
|
#include <cstdio>
#include <iostream>
#include <limits.h>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
ull pow(ull x, ull n) {
ull res = 1;
while (n > 0) {
if (n & 1)
res = res * x;
x = x * x;
n >>= 1;
}
return res;
}
int dic_op(char str[14], int &key) {
int j;
int f = 1;
int g = 0;
for (j = 0; j < 10; j++) {
if (str[j] == 'A')
g += f * 1;
else if (str[j] == 'C')
g += f * 2;
else if (str[j] == 'G')
g += f * 3;
else if (str[j] == 'T')
g += f * 4;
else
break;
f *= 5;
}
key = 0;
if (j == 10) {
f = 1;
for (; j < 10; j++) {
if (str[j] == 'A')
key += f * 1;
else if (str[j] == 'C')
key += f * 2;
else if (str[j] == 'G')
key += f * 3;
else if (str[j] == 'T')
key += f * 4;
else
break;
f *= 5;
}
}
return g;
}
int main() {
int i;
static int dic[10000000];
int n;
char opstr[7];
char str[13];
int key;
cin >> n;
for (i = 0; i < n; i++) {
scanf("%s %s", opstr, str);
if (opstr[0] == 'i') {
int tmp = dic_op(str, key);
if ((dic[tmp] >> key) % 2 == 0) {
dic[tmp] += 1 << key;
}
} else if (opstr[0] == 'f') {
int tmp = dic_op(str, key);
/*
printf("tmp = %d\n",tmp);
printf("key = %d\n",key);
printf("dic[tmp] = %d\n",dic[tmp]);
*/
if ((dic[tmp] >> key) % 2 == 1) {
puts("yes");
} else {
puts("no");
}
}
}
return 0;
}
|
replace
| 63 | 64 | 63 | 64 |
-11
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
set<string> st;
int n;
cin >> n;
while (n--) {
string BUFF, c;
cin >> BUFF >> c;
if (BUFF == "insert")
st.insert(c);
else
cout << (st.find(c) != st.end() ? "yes" : "no") << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
set<string> st;
int n;
cin >> n;
while (n--) {
string BUFF, c;
cin >> BUFF >> c;
if (BUFF == "insert")
st.insert(c);
else
cout << (st.find(c) != st.end() ? "yes" : "no") << endl;
}
}
|
insert
| 6 | 6 | 6 | 7 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define Lim 9999991
#define Jmp 13
int dic[Lim];
int toint(string s) {
int ret = 0;
for (int i = 0; i < s.size(); ++i) {
ret *= 5;
switch (s[i]) {
case 'A':
ret += 1;
break;
case 'T':
ret += 2;
break;
case 'G':
ret += 3;
break;
case 'C':
ret += 4;
break;
}
}
return ret;
}
void push(string s) {
int a = toint(s);
int i = a % Lim;
while (true) {
if (!dic[i]) {
dic[i] = a;
return;
}
i = (i + Jmp) % Lim;
}
}
int find(string s) {
int a = toint(s);
int i = a % Lim;
while (true) {
if (!dic[i]) {
return 0;
}
if (dic[i] == a) {
return 1;
}
i = (i + Jmp) % Lim;
}
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string s, t;
cin >> s >> t;
if (s == "insert") {
push(t);
} else {
if (find(t)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define Lim 9999991
#define Jmp 1000003
int dic[Lim];
int toint(string s) {
int ret = 0;
for (int i = 0; i < s.size(); ++i) {
ret *= 5;
switch (s[i]) {
case 'A':
ret += 1;
break;
case 'T':
ret += 2;
break;
case 'G':
ret += 3;
break;
case 'C':
ret += 4;
break;
}
}
return ret;
}
void push(string s) {
int a = toint(s);
int i = a % Lim;
while (true) {
if (!dic[i]) {
dic[i] = a;
return;
}
i = (i + Jmp) % Lim;
}
}
int find(string s) {
int a = toint(s);
int i = a % Lim;
while (true) {
if (!dic[i]) {
return 0;
}
if (dic[i] == a) {
return 1;
}
i = (i + Jmp) % Lim;
}
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string s, t;
cin >> s >> t;
if (s == "insert") {
push(t);
} else {
if (find(t)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
/*
* ALDS1_4_C.cpp
*
* Created on: Apr 26, 2018
* Author: 13743
*/
#include <cstdio>
using namespace std;
const int SIZE = 1045527;
int table[SIZE];
int getKey(char *s) {
int key = 0;
int exp = 1;
for (int i = 0; s[i] != '\0'; i++) {
switch (s[i]) {
case 'A':
key += 4 * exp;
break;
case 'C':
key += 3 * exp;
break;
case 'G':
key += 2 * exp;
break;
default:
key += 1 * exp;
break;
}
exp *= 5;
}
return key;
}
void insert(char *s) {
int key = getKey(s);
int hash = key % SIZE;
while (true) {
if (table[hash] == 0 || table[hash] == key) {
table[hash] = key;
break;
}
hash = (hash + (1 + (key % (SIZE - 2)))) % SIZE;
}
}
bool find(char *s) {
int key = getKey(s);
int hash = key % SIZE;
int i = 0;
while (i++ < SIZE) {
if (table[hash] == key) {
return true;
}
hash = (hash + (1 + (key % (SIZE - 2)))) % SIZE;
}
return false;
}
int main() {
int n;
scanf("%d", &n);
char d[10];
char s[13];
for (int i = 0; i < n; i++) {
scanf("%s %s", d, s);
;
if (d[0] == 'i') {
insert(s);
} else {
if (find(s))
printf("yes\n");
else
printf("no\n");
}
}
}
|
/*
* ALDS1_4_C.cpp
*
* Created on: Apr 26, 2018
* Author: 13743
*/
#include <cstdio>
using namespace std;
const int SIZE = 1045527;
int table[SIZE];
int getKey(char *s) {
int key = 0;
int exp = 1;
for (int i = 0; s[i] != '\0'; i++) {
switch (s[i]) {
case 'A':
key += 4 * exp;
break;
case 'C':
key += 3 * exp;
break;
case 'G':
key += 2 * exp;
break;
default:
key += 1 * exp;
break;
}
exp *= 5;
}
return key;
}
void insert(char *s) {
int key = getKey(s);
int hash = key % SIZE;
while (true) {
if (table[hash] == 0 || table[hash] == key) {
table[hash] = key;
break;
}
hash = (hash + (1 + (key % (SIZE - 2)))) % SIZE;
}
}
bool find(char *s) {
int key = getKey(s);
int hash = key % SIZE;
int i = 0;
while (i++ < SIZE) {
if (table[hash] == key) {
return true;
} else if (table[hash] == 0) {
return false;
}
hash = (hash + (1 + (key % (SIZE - 2)))) % SIZE;
}
return false;
}
int main() {
int n;
scanf("%d", &n);
char d[10];
char s[13];
for (int i = 0; i < n; i++) {
scanf("%s %s", d, s);
;
if (d[0] == 'i') {
insert(s);
} else {
if (find(s))
printf("yes\n");
else
printf("no\n");
}
}
}
|
insert
| 56 | 56 | 56 | 58 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <cstdio>
#include <cstring>
#include <string>
#define M 5070721
#define NIL (-1)
#define L 14
using namespace std;
typedef long long ll;
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;
else
return 0;
}
ll getKey(char str[]) {
ll sum = 0, p = 1, i;
int len = strlen(str);
for (i = 0; i < len; i++) {
sum += p * (getChar(str[i]));
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
ll key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
ll key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main(void) {
int n;
char str[L], com[9];
for (int i = 0; i < M; i++) {
H[i][0] = '\0';
}
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
#include <cstdio>
#include <cstring>
#include <string>
#define M 5070721
#define NIL (-1)
#define L 14
using namespace std;
typedef long long ll;
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;
else
return 0;
}
ll getKey(char str[]) {
ll sum = 0, p = 1, i;
int len = strlen(str);
for (i = 0; i < len; i++) {
sum += p * (getChar(str[i]));
p *= 5;
}
return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
ll key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0)
return 0;
}
return 0;
}
int insert(char str[]) {
ll key, i, h;
key = getKey(str);
for (i = 0;; i++) {
h = (h1(key) + i * h2(key)) % M;
if (strcmp(H[h], str) == 0)
return 1;
else if (strlen(H[h]) == 0) {
strcpy(H[h], str);
return 0;
}
}
return 0;
}
int main(void) {
int n;
char str[L], com[9];
for (int i = 0; i < M; i++) {
H[i][0] = '\0';
}
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s %s", com, str);
if (com[0] == 'i') {
insert(str);
} else {
if (find(str)) {
printf("yes\n");
} else {
printf("no\n");
}
}
}
return 0;
}
|
insert
| 28 | 28 | 28 | 29 |
TLE
| |
p02269
|
C++
|
Memory Limit Exceeded
|
#include <iostream>
#include <vector>
#define M 10000000
long long StrToID(std::string str) {
long long id = 0;
for (int i = 0; i < str.length(); ++i) {
switch (str[i]) {
case 'A':
id = 1 + id * 10;
break;
case 'C':
id = 2 + id * 10;
break;
case 'G':
id = 3 + id * 10;
break;
case 'T':
id = 4 + id * 10;
break;
default:
break;
}
}
return id;
}
bool includeNum(long long fig, std::vector<long long> S) {
for (int i = 0; i < S.size(); ++i) {
if (S[i] == fig)
return true;
}
return false;
}
int main(int argc, char const *argv[]) {
std::vector<std::vector<long long>> Dictionary(M);
int N, key;
long long id;
std::string cmd, str;
std::cin >> N;
for (int i = 0; i < N; ++i) {
std::cin >> cmd >> str;
id = StrToID(str);
key = id % M;
if (cmd == "insert") {
if (!includeNum(id, Dictionary[key]))
Dictionary[key].push_back(id);
} else if (cmd == "find") {
if (includeNum(id, Dictionary[key])) {
std::cout << "yes" << std::endl;
} else {
std::cout << "no" << std::endl;
}
} else {
// exception
}
}
return 0;
}
|
#include <iostream>
#include <vector>
#define M 1000003
long long StrToID(std::string str) {
long long id = 0;
for (int i = 0; i < str.length(); ++i) {
switch (str[i]) {
case 'A':
id = 1 + id * 10;
break;
case 'C':
id = 2 + id * 10;
break;
case 'G':
id = 3 + id * 10;
break;
case 'T':
id = 4 + id * 10;
break;
default:
break;
}
}
return id;
}
bool includeNum(long long fig, std::vector<long long> S) {
for (int i = 0; i < S.size(); ++i) {
if (S[i] == fig)
return true;
}
return false;
}
int main(int argc, char const *argv[]) {
std::vector<std::vector<long long>> Dictionary(M);
int N, key;
long long id;
std::string cmd, str;
std::cin >> N;
for (int i = 0; i < N; ++i) {
std::cin >> cmd >> str;
id = StrToID(str);
key = id % M;
if (cmd == "insert") {
if (!includeNum(id, Dictionary[key]))
Dictionary[key].push_back(id);
} else if (cmd == "find") {
if (includeNum(id, Dictionary[key])) {
std::cout << "yes" << std::endl;
} else {
std::cout << "no" << std::endl;
}
} else {
// exception
}
}
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
MLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
#define M 1020751
long long convert(string word);
void insert(long long *d, long long key);
int find_key(long long *d, long long key);
int h1(long long key);
int h2(long long key);
int main() {
int i, n;
cin >> n;
string order, word;
long long key;
long long d[M];
queue<string> q;
for (i = 0; i < M; i++) {
d[i] = -1;
}
for (i = 0; i < n; i++) {
cin >> order >> word;
key = convert(word);
if (order[0] == 'i') {
insert(d, key);
} else {
int flag = find_key(d, key);
if (flag == 1) {
q.push("yes");
} else {
q.push("no");
}
}
}
while (!q.empty()) {
cout << q.front() << endl;
q.pop();
}
}
long long convert(string word) {
long long i, num = 0, keta = 1;
for (i = 0; i < word.size(); i++) {
if (word[i] == 'A') {
num += keta;
} else if (word[i] == 'C') {
num += keta * 2;
} else if (word[i] == 'G') {
num += keta * 3;
} else {
num += keta * 4;
}
keta *= 10;
}
return num;
}
void insert(long long *d, long long key) {
int h, i = 1;
h = h1(key);
while (d[h] != -1) {
h = (h1(key) + i * h2(key)) % M;
i++;
}
d[h] = key;
}
int find_key(long long *d, long long key) {
int h, i = 0;
h = h1(key);
while (1) {
if (d[h] == -1) {
return 0;
} else if (d[h] != key) {
i++;
h = (h1(key) + h2(key)) % M;
} else {
return 1;
}
}
}
int h1(long long key) { return key % M; }
int h2(long long key) { return 1 + (key % (M - 1)); }
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
#define M 1020751
long long convert(string word);
void insert(long long *d, long long key);
int find_key(long long *d, long long key);
int h1(long long key);
int h2(long long key);
int main() {
int i, n;
cin >> n;
string order, word;
long long key;
long long d[M];
queue<string> q;
for (i = 0; i < M; i++) {
d[i] = -1;
}
for (i = 0; i < n; i++) {
cin >> order >> word;
key = convert(word);
if (order[0] == 'i') {
insert(d, key);
} else {
int flag = find_key(d, key);
if (flag == 1) {
q.push("yes");
} else {
q.push("no");
}
}
}
while (!q.empty()) {
cout << q.front() << endl;
q.pop();
}
}
long long convert(string word) {
long long i, num = 0, keta = 1;
for (i = 0; i < word.size(); i++) {
if (word[i] == 'A') {
num += keta;
} else if (word[i] == 'C') {
num += keta * 2;
} else if (word[i] == 'G') {
num += keta * 3;
} else {
num += keta * 4;
}
keta *= 10;
}
return num;
}
void insert(long long *d, long long key) {
int h, i = 1;
h = h1(key);
while (d[h] != -1) {
h = (h1(key) + i * h2(key)) % M;
i++;
}
d[h] = key;
}
int find_key(long long *d, long long key) {
int h, i = 0;
h = h1(key);
while (1) {
if (d[h] == -1) {
return 0;
} else if (d[h] != key) {
i++;
h = (h1(key) + i * h2(key)) % M;
} else {
return 1;
}
}
}
int h1(long long key) { return key % M; }
int h2(long long key) { return 1 + (key % (M - 1)); }
|
replace
| 79 | 80 | 79 | 80 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;
struct Dict {
Dict() : buf_(initial_buf_size, list<string>()) {}
void Insert(const string &s) {
auto h = StrHash(s) % buf_.size();
auto &slot = buf_[h];
if (!FindInternal(slot, s)) {
slot.push_front(s);
}
}
bool Find(const string &s) const {
auto h = StrHash(s) % buf_.size();
auto &slot = buf_[h];
return FindInternal(slot, s);
}
private:
constexpr static auto initial_buf_size = 1024;
bool FindInternal(const list<string> &slot, const string &s) const {
return find_if(slot.begin(), slot.end(), [&](const string &s0) {
return !s0.compare(s);
}) != slot.end();
}
static size_t StrHash(const string &s) {
size_t hash = 17;
for (auto &&c : s) {
hash += (hash * 23) + static_cast<size_t>(c) * 7;
}
return hash;
}
vector<list<string>> buf_;
};
int main() {
int n;
cin >> n;
Dict dic;
for (int i = 0; i < n; ++i) {
string cmd;
string str;
cin >> cmd >> str;
if (!cmd.compare("insert")) {
dic.Insert(str);
} else {
cout << (dic.Find(str) ? "yes" : "no") << endl;
}
}
}
|
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;
struct Dict {
Dict() : buf_(initial_buf_size, list<string>()) {}
void Insert(const string &s) {
auto h = StrHash(s) % buf_.size();
auto &slot = buf_[h];
if (!FindInternal(slot, s)) {
slot.push_front(s);
}
}
bool Find(const string &s) const {
auto h = StrHash(s) % buf_.size();
auto &slot = buf_[h];
return FindInternal(slot, s);
}
private:
constexpr static auto initial_buf_size = 1024 * 1024;
bool FindInternal(const list<string> &slot, const string &s) const {
return find_if(slot.begin(), slot.end(), [&](const string &s0) {
return !s0.compare(s);
}) != slot.end();
}
static size_t StrHash(const string &s) {
size_t hash = 17;
for (auto &&c : s) {
hash += (hash * 23) + static_cast<size_t>(c) * 7;
}
return hash;
}
vector<list<string>> buf_;
};
int main() {
int n;
cin >> n;
Dict dic;
for (int i = 0; i < n; ++i) {
string cmd;
string str;
cin >> cmd >> str;
if (!cmd.compare("insert")) {
dic.Insert(str);
} else {
cout << (dic.Find(str) ? "yes" : "no") << endl;
}
}
}
|
replace
| 30 | 31 | 30 | 31 |
TLE
| |
p02269
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
string PopFront(string X) {
string Y;
for (int i = 1; i < X.size(); i++) {
Y.push_back(X[i]);
}
return Y;
}
bool operator<(string &A, string &B) {
int a = 0;
int b = 0;
while (!A.empty() && !B.empty()) {
if ('A[0]' < 'B[0]') {
a = 1;
break;
} else if ('A[0]' > 'B[0]') {
b = 1;
break;
}
A = PopFront(A);
B = PopFront(B);
}
if (!A.empty()) {
a = 1;
} else if (!B.empty()) {
b = 1;
}
return a < b;
}
void Judge(set<string> &RWord, string &Command, string &Word) {
if (Command == "insert") {
RWord.insert(Word);
} else {
if (binary_search(RWord.begin(), RWord.end(), Word)) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
set<string> RWord;
for (int i = 0; i < n; i++) {
string Command;
string Word;
cin >> Command;
cin >> Word;
Judge(RWord, Command, Word);
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
string PopFront(string X) {
string Y;
for (int i = 1; i < X.size(); i++) {
Y.push_back(X[i]);
}
return Y;
}
bool operator<(string &A, string &B) {
int a = 0;
int b = 0;
while (!A.empty() && !B.empty()) {
if ('A[0]' < 'B[0]') {
a = 1;
break;
} else if ('A[0]' > 'B[0]') {
b = 1;
break;
}
A = PopFront(A);
B = PopFront(B);
}
if (!A.empty()) {
a = 1;
} else if (!B.empty()) {
b = 1;
}
return a < b;
}
void Judge(set<string> &RWord, string &Command, string &Word) {
if (Command == "insert") {
RWord.insert(Word);
} else {
set<string>::iterator it = RWord.find(Word);
if (it != RWord.end()) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
set<string> RWord;
for (int i = 0; i < n; i++) {
string Command;
string Word;
cin >> Command;
cin >> Word;
Judge(RWord, Command, Word);
}
return 0;
}
|
replace
| 40 | 41 | 40 | 42 |
TLE
| |
p02270
|
C++
|
Time Limit Exceeded
|
/**************
* Allocation
*************/
#include <algorithm>
#include <iostream>
#include <numeric> //??¢??°
#include <vector> //??£?¨?
using namespace std;
//??\???
vector<int> getLoadList(int n) //??????????????°
{
vector<int> loadList(n); //?????????
for (int i = 0; i < n; i++) {
cin >> loadList[i];
}
return loadList; //????????????
}
//??????
bool check(vector<int> loadList, int k, int minP) {
int truck = 1;
int sum = 0;
for (int i = 0; i < loadList.size(); i++) {
if (minP < (sum + loadList[i])) { //
truck++;
sum = 0; //??????????????????
}
sum += loadList[i];
}
if (k < truck) {
//????????????????????????????????????????????????????????£??????
return false;
}
return true;
}
int main() {
//???????????°n??¨?????????????????°k??????????????????
int n;
cin >> n;
int k;
cin >> k;
//?????????????????°??§??????????????????????????????
vector<int> loadList = getLoadList(n);
//?????????????±???????
int minP = accumulate(loadList.begin(), loadList.end(), 0) / n;
//?????????????????§??????
// int minP = aveload+1;
// minP????????§???????´???\???
int max = (*max_element(loadList.begin(), loadList.end()));
int maxP = ((double)n / k) * max;
//?????????????????????????????¢??°???????????????????????°??????????????°??????????????????
while ((minP + 1) != maxP) {
int p = (maxP + minP) / 2;
if ((p >= max) && (check(loadList, k, p))) {
maxP = p;
} else {
minP = p;
}
}
//?????§????????? P???????°?????????????
cout << maxP << endl;
return 0;
}
|
/**************
* Allocation
*************/
#include <algorithm>
#include <iostream>
#include <numeric> //??¢??°
#include <vector> //??£?¨?
using namespace std;
//??\???
vector<int> getLoadList(int n) //??????????????°
{
vector<int> loadList(n); //?????????
for (int i = 0; i < n; i++) {
cin >> loadList[i];
}
return loadList; //????????????
}
//??????
bool check(vector<int> loadList, int k, int minP) {
int truck = 1;
int sum = 0;
for (int i = 0; i < loadList.size(); i++) {
if (minP < (sum + loadList[i])) { //
truck++;
sum = 0; //??????????????????
}
sum += loadList[i];
}
if (k < truck) {
//????????????????????????????????????????????????????????£??????
return false;
}
return true;
}
int main() {
//???????????°n??¨?????????????????°k??????????????????
int n;
cin >> n;
int k;
cin >> k;
//?????????????????°??§??????????????????????????????
vector<int> loadList = getLoadList(n);
//?????????????±???????
int minP = accumulate(loadList.begin(), loadList.end(), 0) / n - 1;
//?????????????????§??????
// int minP = aveload+1;
// minP????????§???????´???\???
int max = (*max_element(loadList.begin(), loadList.end()));
int maxP = ((double)n / k) * max;
//?????????????????????????????¢??°???????????????????????°??????????????°??????????????????
while ((minP + 1) != maxP) {
int p = (maxP + minP) / 2;
if ((p >= max) && (check(loadList, k, p))) {
maxP = p;
} else {
minP = p;
}
}
//?????§????????? P???????°?????????????
cout << maxP << endl;
return 0;
}
|
replace
| 52 | 53 | 52 | 53 |
TLE
| |
p02270
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long llong;
int n, k;
llong T[MAX];
int check(llong P) {
int i = 0;
for (int j = 0; j < k; j++) {
llong s = 0;
while (s + T[i] <= P) {
s += T[i];
i++;
if (i == n)
return n;
}
}
return i;
}
int solve() {
llong left = 0;
llong right = 100000 * 10000;
llong mid;
while (right > left) {
mid = (left + right) / 2;
int v = check(mid);
if (v >= n)
right = mid;
else
left = mid;
}
return right;
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> T[i];
llong ans = solve();
cout << ans << endl;
return 0;
}
|
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long llong;
int n, k;
llong T[MAX];
int check(llong P) {
int i = 0;
for (int j = 0; j < k; j++) {
llong s = 0;
while (s + T[i] <= P) {
s += T[i];
i++;
if (i == n)
return n;
}
}
return i;
}
int solve() {
llong left = 0;
llong right = 100000 * 10000;
llong mid;
while (right - left > 1) {
mid = (left + right) / 2;
int v = check(mid);
if (v >= n)
right = mid;
else
left = mid;
}
return right;
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> T[i];
llong ans = solve();
cout << ans << endl;
return 0;
}
|
replace
| 26 | 27 | 26 | 27 |
TLE
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.