Submission #421631

# Submission time Handle Problem Language Result Execution time Memory
421631 2021-06-09T10:14:01 Z urd05 Zagrade (COI20_zagrade) C++14
100 / 100
1076 ms 804 KB
#include <bits/stdc++.h>
using namespace std;

char str[100002];

int main(void) {
    stack<int> s;
    s.push(1);
    int n,q;
    scanf("%d %d",&n,&q);
    for(int i=2;i<=n;i++) {
        if (s.empty()) {
            s.push(i);
            continue;
        }
        printf("? %d %d\n",s.top(),i);
        fflush(stdout);
        int x;
        scanf("%d",&x);
        if (x==1) {
            str[s.top()]='(';
            str[i]=')';
            s.pop();
        }
        else {
            s.push(i);
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++) {
        if (str[i]==0) {
            cnt++;
        }
    }
    int cnt2=cnt/2;
    for(int i=1;i<=n;i++) {
        if (str[i]==0) {
            if (cnt2>0) {
                cnt2--;
                str[i]=')';
            }
            else {
               str[i]='('; 
            }
        }
    }
    printf("! %s\n",str+1);
    fflush(stdout);
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~
zagrade.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d",&x);
      |         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 288 KB Output is correct
2 Correct 6 ms 200 KB Output is correct
3 Correct 14 ms 256 KB Output is correct
4 Correct 18 ms 244 KB Output is correct
5 Correct 10 ms 200 KB Output is correct
6 Correct 10 ms 200 KB Output is correct
7 Correct 8 ms 296 KB Output is correct
8 Correct 9 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 200 KB Output is correct
2 Correct 14 ms 200 KB Output is correct
3 Correct 10 ms 200 KB Output is correct
4 Correct 17 ms 280 KB Output is correct
5 Correct 5 ms 288 KB Output is correct
6 Correct 7 ms 200 KB Output is correct
7 Correct 12 ms 200 KB Output is correct
8 Correct 6 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 546 ms 372 KB Output is correct
3 Correct 861 ms 372 KB Output is correct
4 Correct 1036 ms 380 KB Output is correct
5 Correct 600 ms 376 KB Output is correct
6 Correct 942 ms 368 KB Output is correct
7 Correct 895 ms 776 KB Output is correct
8 Correct 719 ms 584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 835 ms 804 KB Output is correct
3 Correct 1076 ms 476 KB Output is correct
4 Correct 882 ms 580 KB Output is correct
5 Correct 912 ms 464 KB Output is correct
6 Correct 872 ms 600 KB Output is correct
7 Correct 576 ms 452 KB Output is correct
8 Correct 998 ms 372 KB Output is correct