답안 #997165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997165 2024-06-11T18:40:08 Z oscarsierra12 Zagrade (COI20_zagrade) C++14
71 / 100
1218 ms 1244 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;
const ll maxn=1e5+5;
const int INF=1e9+5;
#define ok ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define endl '\n'
int n, q, bk, ttp, jwb, rem, nah[maxn];
stack<int> st;
char ans[maxn];
int main() {
    ok
    cin >> n >> q;
    if(q==n*n/4) {
        for(int i=1; i<n; i++) {
            for(int j=i+1; j<=n; j+=2) {
                cout << "? " << i << " " << j << endl;
                cout.flush();
                cin >> jwb;
                if(jwb==1) {
                    nah[i]=1;
                    nah[j]=2;
                    break;
                }
            }
        }
        for(int i=1; i<=n; i++) {
            if(!nah[i]) {
                rem++;
            }
        }
        rem/=2;
        for(int i=1; i<=n; i++) {
            if(rem && !nah[i]) {
                nah[i]=2;
                rem--;
            } else if(!nah[i]) nah[i]=1;
        }
        cout << "! ";
        for(int i=1; i<=n; i++) {
            if(nah[i]==1) cout << '(';
            else cout << ')';
        }
        cout << endl;
        return 0;
    }
    for(int i=1; i<=n; i++) {
        if(st.empty()) {
            ans[i]='(';
            st.push(i);
            continue;
        }
        cout << "? " << st.top() << " " << i << endl;
        cout.flush();
        cin >> jwb;
        if(jwb==1) {
            ans[i]=')';
            st.pop();
        } else {
            ans[i]='(';
            st.push(i);
        }
    }
    cout << "! ";
    for(int i=1; i<=n; i++) {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 731 ms 444 KB Output is correct
3 Correct 778 ms 600 KB Output is correct
4 Correct 759 ms 344 KB Output is correct
5 Correct 725 ms 344 KB Output is correct
6 Correct 766 ms 596 KB Output is correct
7 Correct 1115 ms 344 KB Output is correct
8 Correct 636 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1218 ms 440 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 254 ms 748 KB Output is correct
3 Correct 595 ms 784 KB Output is correct
4 Correct 593 ms 1008 KB Output is correct
5 Correct 591 ms 964 KB Output is correct
6 Correct 603 ms 980 KB Output is correct
7 Correct 613 ms 1088 KB Output is correct
8 Correct 620 ms 1244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Mismatch at position 1. Expected ), found (
2 Halted 0 ms 0 KB -