답안 #411947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411947 2021-05-26T10:23:17 Z 반딧불(#7584) Zagrade (COI20_zagrade) C++17
100 / 100
984 ms 844 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, q;
char arr[100002];
stack<int> stk;

int main(){
    scanf("%d %d", &n, &q);
    for(int i=1; i<=n; i++){
        if(stk.empty()) stk.push(i);
        else{
            printf("? %d %d\n", stk.top(), i);
            fflush(stdout);

            int ret;
            scanf("%d", &ret);
            if(!ret) stk.push(i);
            else{
                arr[stk.top()] = '(';
                arr[i] = ')';
                stk.pop();
            }
        }
    }

    int s = (int)stk.size() / 2;
    while((int)stk.size() > s){
        arr[stk.top()] = '(';
        stk.pop();
    }
    while(!stk.empty()){
        arr[stk.top()] = ')';
        stk.pop();
    }
    printf("! %s", arr+1);
    fflush(stdout);
    return 0;
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
zagrade.cpp:20:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |             scanf("%d", &ret);
      |             ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 7 ms 200 KB Output is correct
3 Correct 14 ms 200 KB Output is correct
4 Correct 13 ms 200 KB Output is correct
5 Correct 14 ms 200 KB Output is correct
6 Correct 12 ms 200 KB Output is correct
7 Correct 5 ms 204 KB Output is correct
8 Correct 11 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 13 ms 200 KB Output is correct
3 Correct 13 ms 200 KB Output is correct
4 Correct 12 ms 300 KB Output is correct
5 Correct 11 ms 200 KB Output is correct
6 Correct 13 ms 200 KB Output is correct
7 Correct 8 ms 200 KB Output is correct
8 Correct 8 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 568 ms 440 KB Output is correct
3 Correct 710 ms 372 KB Output is correct
4 Correct 935 ms 600 KB Output is correct
5 Correct 984 ms 468 KB Output is correct
6 Correct 881 ms 444 KB Output is correct
7 Correct 852 ms 616 KB Output is correct
8 Correct 889 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 927 ms 844 KB Output is correct
3 Correct 979 ms 440 KB Output is correct
4 Correct 960 ms 608 KB Output is correct
5 Correct 778 ms 656 KB Output is correct
6 Correct 504 ms 700 KB Output is correct
7 Correct 965 ms 480 KB Output is correct
8 Correct 732 ms 576 KB Output is correct