Submission #976839

# Submission time Handle Problem Language Result Execution time Memory
976839 2024-05-07T07:32:51 Z efedmrlr Zagrade (COI20_zagrade) C++17
14 / 100
540 ms 600 KB
#include <bits/stdc++.h>

#define lli long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)

using namespace std;

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N = 1e5 + 5;
const int INF = 1e9 + 500;
vector<char> res(N);
int n, q;
bool query(int l, int r) {
    cout << "? " << l << " " << r << endl;
    bool x;
    cin >> x;
    return x;
}
void answer() {
    cout << "! ";
    for(int i = 1; i <= n; i++) {
        cout << res[i];
    }
    cout << endl;
}
void sol_sub(int l, int r) {
    if(l + 1 > r) return;
    if(l + 1 == r) {
        res[l] = '(';
        res[r] = ')';
        return;
    }
    bool x = query(l + 1, r - 1);
    if(x) {
        res[l] = '(';
        res[r] = ')';
        sol_sub(l + 1, r - 1);
        return;
    }
    for(int nr = l + 1; nr < r; nr+=2) {
        x = query(l, nr);
        if(x) {
            sol_sub(l, nr);
            sol_sub(nr + 1, r);
            return;
        }
    } 
}

void solve() {
    cin >> n >> q;

    sol_sub(1, n);
    answer();
}


signed main() { 
    fastio();
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 5 ms 600 KB Output is correct
3 Correct 13 ms 524 KB Output is correct
4 Correct 12 ms 552 KB Output is correct
5 Correct 14 ms 600 KB Output is correct
6 Correct 8 ms 552 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 10 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 540 ms 536 KB Output is correct
3 Runtime error 482 ms 544 KB Execution killed with signal 13
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Mismatch at position 1. Expected ), found
2 Halted 0 ms 0 KB -