Submission #1003770

# Submission time Handle Problem Language Result Execution time Memory
1003770 2024-06-20T17:22:03 Z vjudge1 Zagrade (COI20_zagrade) C++17
100 / 100
588 ms 1368 KB
#include <bits/stdc++.h>
using namespace std;

int main(){

    int n,q; cin >> n >> q;

    string res = string(n, '?');

    stack<int> ultimo;

       
    int i=1;

    while(i<n){
        cout << "? "<< i << ' '<< i+1 << endl;
        int ans; cin >> ans;

        if(ans == 1){
            res[i-1] = '('; res[i]=')';
            i = i+2;
            while(ultimo.size()!=0 and i<= n){
                cout << "? "<< ultimo.top()<< ' '<< i << endl;
                int outro; cin >> outro;
                if(outro == 1){
                    res[ultimo.top()-1]='('; res[i-1] = ')';
                    i++; ultimo.pop();
                }
                else break;
            }
        }
        else{
            ultimo.push(i); i++;
        }
    }

    int falta=0;
    for(auto j: res) if(j == '?') falta++;
    int qnt = 0;

    for(int j=0; j<res.size(); j++){
        if(res[j] != '?')continue;
        if(qnt <(falta/2)) res[j] = ')';
        else res[j] = '(';
        qnt++;
    }
    cout << "! "<< res << endl;
     
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:41:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int j=0; j<res.size(); j++){
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 6 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 5 ms 344 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 5 ms 344 KB Output is correct
8 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 295 ms 524 KB Output is correct
3 Correct 583 ms 508 KB Output is correct
4 Correct 572 ms 512 KB Output is correct
5 Correct 584 ms 508 KB Output is correct
6 Correct 574 ms 512 KB Output is correct
7 Correct 572 ms 1064 KB Output is correct
8 Correct 577 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 588 ms 1368 KB Output is correct
3 Correct 577 ms 812 KB Output is correct
4 Correct 552 ms 1356 KB Output is correct
5 Correct 545 ms 1048 KB Output is correct
6 Correct 527 ms 1148 KB Output is correct
7 Correct 516 ms 1328 KB Output is correct
8 Correct 525 ms 512 KB Output is correct