Submission #1123061

#TimeUsernameProblemLanguageResultExecution timeMemory
1123061thangdz2k7Zagrade (COI20_zagrade)C++20
71 / 100
337 ms840 KiB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;

const int MaxN = 2e5;
const int mod = 1e9 + 7;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

bool ask(int a, int b){
    cout << "? " << a + 1 << ' ' << b + 1 << endl;
    int t; cin >> t;
    return t;
}

void solve(){
    int n, q; cin >> n >> q;
    string ans;
    ans.resize(n);
    ans[0] = '(';
    vector <int> stk = {0};
    for (int i = 1; i < n - 1; ++ i){
        if (stk.empty() || !ask(stk.back(), i)){
            ans[i] = '(';
            stk.pb(i);
        }
        else {
            ans[i] = ')';
            stk.pop_back();
        }
    }
    ans[n - 1] = ')';

    cout << "! " << ans << endl;
}

int main(){
    if (fopen("pqh.inp", "r")){
        freopen("pqh.inp", "r", stdin);
        freopen("pqh.out", "w", stdout);
    }

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message (stderr)

zagrade.cpp: In function 'int main()':
zagrade.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen("pqh.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
zagrade.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen("pqh.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...