답안 #559100

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
559100 2022-05-09T11:33:45 Z Redhood Zagrade (COI20_zagrade) C++14
0 / 100
0 ms 336 KB
#include<bits/stdc++.h>

#define fi first
#define se second
#define sz(x) (int)(x).size()
#define pb push_back
#define mkp make_pair
using namespace std;

typedef long long ll;
typedef long double ld;


bool ask(int i , int j){
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    int ans;
    cin >> ans;
    return ans;
}
signed main(){
    int n , q;
    cin >> n >> q;

    stack < int > pos;

    pos.push(0);



    string s = string(n,  '(');

    int did=0;

    int need = n / 2;

    cout << s << endl;
    for(int i = 1; i < n; ++i){
        if(pos.empty()){
            pos.push(i);
            continue;
        }
        int f = pos.top();

        if(ask(f , i)){
            s[f] = '(';
            s[i] = ')';
            did++;
            pos.pop();
        }else{
            pos.push(i);
        }
    }


    assert(sz(pos) % 2 == 0);
    int f = sz(pos) / 2;

    for(int t=0;t<f;++t){
        s[pos.top()] = '(';
        pos.pop();
    }
    for(int t=0;t<f;++t){
        s[pos.top()] = ')';
        pos.pop();
    }
    cout << "! " << s << endl;

    return 0;
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:34:9: warning: unused variable 'need' [-Wunused-variable]
   34 |     int need = n / 2;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 336 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -