Submission #777736

# Submission time Handle Problem Language Result Execution time Memory
777736 2023-07-09T14:38:06 Z dxz05 Mađioničar (COI22_madionicar) C++17
100 / 100
1514 ms 328 KB
//#pragma GCC optimize("Ofast,O3,unroll-loops")
//#pragma GCC target("avx,avx2")

#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define MP make_pair
//#define endl '\n'

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

typedef long long ll;
const int MOD = 1e9 + 7;
const int N = 1e5 + 3e2;

int queries;
string hidden_string;

int ask(int l, int r){
    queries++;

    if (!hidden_string.empty()){
        string t = hidden_string.substr(l, r - l + 1);
        string rt = string(rall(t));
        return t == rt;
    }

    cout << "? " << l + 1 << ' ' << r + 1 << endl;
    int res;
    cin >> res;
    return res;
}

void solve(){
//    hidden_string = "neven";

    int n;
    if (hidden_string.empty()){
        cin >> n;
    } else {
        n = (int) hidden_string.size();
    }

    int odd = 3;
    for (int i = 0; i < n; i++){
        while (true){
            int l = i - odd / 2, r = i + odd / 2;
            if (0 <= l && r < n && ask(l, r)){
                odd += 2;
            } else {
                break;
            }
        }
    }

    int even = 2;
    for (int i = 0; i < n; i++){
        while (true){
            int l = i - even / 2 + 1, r = i + even / 2;
            if (0 <= l && r < n && ask(l, r)){
                even += 2;
            } else {
                break;
            }
        }
    }

    cerr << "Queries -> " << queries << endl;

    cout << "! " << max(odd, even) - 2 << endl;

}

int main(){
    clock_t startTime = clock();
    ios_base::sync_with_stdio(false);

#ifdef LOCAL
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif

    int test_cases = 1;
//    cin >> test_cases;

    for (int test = 1; test <= test_cases; test++){
        // cout << (solve() ? "YES" : "NO") << endl;
        solve();
    }

#ifdef LOCAL
    cerr << "Time: " << int((double) (clock() - startTime) / CLOCKS_PER_SEC * 1000) << " ms" << endl;
#endif

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:80:13: warning: unused variable 'startTime' [-Wunused-variable]
   80 |     clock_t startTime = clock();
      |             ^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 96 ms 296 KB Output is correct
2 Correct 73 ms 300 KB Output is correct
3 Correct 127 ms 208 KB Output is correct
4 Correct 119 ms 300 KB Output is correct
5 Correct 85 ms 296 KB Output is correct
6 Correct 68 ms 300 KB Output is correct
7 Correct 97 ms 304 KB Output is correct
8 Correct 119 ms 296 KB Output is correct
9 Correct 114 ms 300 KB Output is correct
10 Correct 108 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 296 KB Output is correct
2 Correct 73 ms 300 KB Output is correct
3 Correct 127 ms 208 KB Output is correct
4 Correct 119 ms 300 KB Output is correct
5 Correct 85 ms 296 KB Output is correct
6 Correct 68 ms 300 KB Output is correct
7 Correct 97 ms 304 KB Output is correct
8 Correct 119 ms 296 KB Output is correct
9 Correct 114 ms 300 KB Output is correct
10 Correct 108 ms 208 KB Output is correct
11 Correct 577 ms 304 KB Output is correct
12 Correct 779 ms 300 KB Output is correct
13 Correct 973 ms 296 KB Output is correct
14 Correct 969 ms 296 KB Output is correct
15 Correct 971 ms 304 KB Output is correct
16 Correct 823 ms 312 KB Output is correct
17 Correct 849 ms 304 KB Output is correct
18 Correct 875 ms 296 KB Output is correct
19 Correct 880 ms 296 KB Output is correct
20 Correct 923 ms 296 KB Output is correct
21 Correct 887 ms 316 KB Output is correct
22 Correct 869 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1068 ms 296 KB Output is correct
2 Correct 831 ms 300 KB Output is correct
3 Correct 1018 ms 304 KB Output is correct
4 Correct 1092 ms 300 KB Output is correct
5 Correct 1255 ms 300 KB Output is correct
6 Correct 904 ms 304 KB Output is correct
7 Correct 1062 ms 300 KB Output is correct
8 Correct 1212 ms 300 KB Output is correct
9 Correct 1309 ms 300 KB Output is correct
10 Correct 1090 ms 300 KB Output is correct
11 Correct 1406 ms 296 KB Output is correct
12 Correct 1300 ms 300 KB Output is correct
13 Correct 1182 ms 300 KB Output is correct
14 Correct 1207 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 296 KB Output is correct
2 Correct 73 ms 300 KB Output is correct
3 Correct 127 ms 208 KB Output is correct
4 Correct 119 ms 300 KB Output is correct
5 Correct 85 ms 296 KB Output is correct
6 Correct 68 ms 300 KB Output is correct
7 Correct 97 ms 304 KB Output is correct
8 Correct 119 ms 296 KB Output is correct
9 Correct 114 ms 300 KB Output is correct
10 Correct 108 ms 208 KB Output is correct
11 Correct 577 ms 304 KB Output is correct
12 Correct 779 ms 300 KB Output is correct
13 Correct 973 ms 296 KB Output is correct
14 Correct 969 ms 296 KB Output is correct
15 Correct 971 ms 304 KB Output is correct
16 Correct 823 ms 312 KB Output is correct
17 Correct 849 ms 304 KB Output is correct
18 Correct 875 ms 296 KB Output is correct
19 Correct 880 ms 296 KB Output is correct
20 Correct 923 ms 296 KB Output is correct
21 Correct 887 ms 316 KB Output is correct
22 Correct 869 ms 304 KB Output is correct
23 Correct 1068 ms 296 KB Output is correct
24 Correct 831 ms 300 KB Output is correct
25 Correct 1018 ms 304 KB Output is correct
26 Correct 1092 ms 300 KB Output is correct
27 Correct 1255 ms 300 KB Output is correct
28 Correct 904 ms 304 KB Output is correct
29 Correct 1062 ms 300 KB Output is correct
30 Correct 1212 ms 300 KB Output is correct
31 Correct 1309 ms 300 KB Output is correct
32 Correct 1090 ms 300 KB Output is correct
33 Correct 1406 ms 296 KB Output is correct
34 Correct 1300 ms 300 KB Output is correct
35 Correct 1182 ms 300 KB Output is correct
36 Correct 1207 ms 296 KB Output is correct
37 Correct 1405 ms 300 KB Output is correct
38 Correct 1304 ms 300 KB Output is correct
39 Correct 1049 ms 328 KB Output is correct
40 Correct 1214 ms 300 KB Output is correct
41 Correct 1195 ms 300 KB Output is correct
42 Correct 1301 ms 208 KB Output is correct
43 Correct 1204 ms 296 KB Output is correct
44 Correct 1241 ms 296 KB Output is correct
45 Correct 1226 ms 308 KB Output is correct
46 Correct 1274 ms 300 KB Output is correct
47 Correct 1257 ms 312 KB Output is correct
48 Correct 1333 ms 296 KB Output is correct
49 Correct 1499 ms 300 KB Output is correct
50 Correct 1155 ms 300 KB Output is correct
51 Correct 1268 ms 316 KB Output is correct
52 Correct 1514 ms 300 KB Output is correct