Submission #781311

# Submission time Handle Problem Language Result Execution time Memory
781311 2023-07-13T02:44:07 Z makanhulia Zagrade (COI20_zagrade) C++17
100 / 100
728 ms 1440 KB
# include <bits/stdc++.h>
# define int long long
# define vi vector<int>
# define pb push_back
# define pii pair<int, int>
# define fi first
# define se second
# define endl '\n'

using namespace std;

char ans[100005];

bool ask(int a, int b) {
    cout << "? " << a << " " << b << endl << flush;
    int ret; cin >> ret;
    return ret;
}

void solve() {
    int n, q;
    cin >> n >> q;
    stack<int> s;
    s.push(1);
    int cnt=0;
    for(int i=1; i<=n; i++) ans[i]='-';
    for(int i=2; i<=n; i++) {
        if(s.empty()) {
            s.push(i);
            continue;
        }
        if(ask(s.top(), i)) {
            ans[s.top()]='(';
            ans[i]=')';
            cnt++;
            s.pop();
        } else {
            s.push(i);
        }
    }
    int tmp=(n/2)-cnt;
    for(int i=1; i<=n; i++) {
        if(ans[i]=='-') {
            if(tmp>0) {
                ans[i]=')';
                tmp--;
            } else ans[i]='(';
        }
    }
    cout << "! ";
    for(int i=1; i<=n; i++) cout << ans[i];
    cout << endl << flush;
}
 
signed main() {
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 5 ms 208 KB Output is correct
3 Correct 7 ms 208 KB Output is correct
4 Correct 13 ms 208 KB Output is correct
5 Correct 7 ms 208 KB Output is correct
6 Correct 7 ms 208 KB Output is correct
7 Correct 4 ms 208 KB Output is correct
8 Correct 9 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 7 ms 312 KB Output is correct
3 Correct 8 ms 308 KB Output is correct
4 Correct 8 ms 208 KB Output is correct
5 Correct 7 ms 312 KB Output is correct
6 Correct 7 ms 208 KB Output is correct
7 Correct 9 ms 208 KB Output is correct
8 Correct 8 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 332 ms 336 KB Output is correct
3 Correct 568 ms 336 KB Output is correct
4 Correct 728 ms 336 KB Output is correct
5 Correct 686 ms 336 KB Output is correct
6 Correct 662 ms 336 KB Output is correct
7 Correct 600 ms 796 KB Output is correct
8 Correct 635 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 698 ms 1440 KB Output is correct
3 Correct 567 ms 472 KB Output is correct
4 Correct 615 ms 784 KB Output is correct
5 Correct 601 ms 588 KB Output is correct
6 Correct 639 ms 880 KB Output is correct
7 Correct 697 ms 552 KB Output is correct
8 Correct 609 ms 380 KB Output is correct