Submission #1018514

# Submission time Handle Problem Language Result Execution time Memory
1018514 2024-07-10T06:25:17 Z kukuk Zagrade (COI20_zagrade) C++14
100 / 100
586 ms 1812 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int ukr = 1e5+10;
ll n, m, id, a, b;
char ar[ukr];
vector<int> v;
int ask(int a, int b){
    cout << "? " << a << " " << b << endl;
    int kkl;
    cin >> kkl;
    return kkl;
}
void solve(){
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        ar[i] = '.';
    }
    ll pke = 0;
    for(int i = 1; i <= n; i++){
        if(v.empty()){
            v.push_back(i);
        }else{
            if(ask(v.back(), i)){
                ar[v.back()] = '(';
                ar[i] = ')';
                v.pop_back();
                pke += 2;
            }else{
                v.push_back(i);
            }
        }
    }
    pke = n-pke;
    pke/=2;
    cout << "! ";
    for(int i = 1; i <= n; i++){
        if(ar[i] == '.'){
            if(!pke){
                ar[i] = '(';
            }else{
                pke--;
                ar[i] = ')';
            }
        }
        cout << ar[i];
    }
  	cout << endl;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 6 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 5 ms 460 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 6 ms 460 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 250 ms 528 KB Output is correct
3 Correct 533 ms 528 KB Output is correct
4 Correct 554 ms 532 KB Output is correct
5 Correct 556 ms 528 KB Output is correct
6 Correct 548 ms 524 KB Output is correct
7 Correct 557 ms 1452 KB Output is correct
8 Correct 586 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 543 ms 1812 KB Output is correct
3 Correct 574 ms 1144 KB Output is correct
4 Correct 522 ms 1396 KB Output is correct
5 Correct 575 ms 1172 KB Output is correct
6 Correct 553 ms 1428 KB Output is correct
7 Correct 555 ms 1024 KB Output is correct
8 Correct 565 ms 532 KB Output is correct