Submission #641578

# Submission time Handle Problem Language Result Execution time Memory
641578 2022-09-17T05:11:12 Z andecaandeci Zagrade (COI20_zagrade) C++17
100 / 100
882 ms 5532 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() 
{
    cin.tie(0); ios_base::sync_with_stdio(0);

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

    vector<int> ans(n, -1);
    set<int> s;
    s.insert(0);
    for(int i = 1; i < n; i++) {
        if(ans[i] != -1) continue;
        // cout << "Masuk " << i << '\n';
        while(!s.empty()) {
            int l = *s.rbegin(), r = i;
            if(l >= 0 && r < n) {
                cout << "? " << l + 1 << " " << r + 1 << endl;
                int x; cin >> x;
                if(x) {
                    ans[l] = 1;
                    ans[r] = 0;
                    s.erase(l);
                    i++;
                } else {
                    s.insert(r);
                    break;
                }
            } else {
                break;
            }
        }
        if(s.empty() && ans[i] == -1) s.insert(i);
    }

    int x = 0;
    for(int i = 0; i < n; i++) x += ans[i] == -1;
    x /= 2;

    while(!s.empty()) s.erase(s.begin());

    bool ok = 0;
    for(int i = 0; i < n; i++) {
        if(ans[i] != -1) continue;
        if(s.size() >= x) ok = 1;
        if(!ok) s.insert(i);
        if(ok) {
            // cout << *s.rbegin() << '\n';
            ans[*s.rbegin()] = 0;
            ans[i] = 1;
            s.erase(*s.rbegin());
        }
    }

    cout << "! ";
    for(int i = 0; i < n; i++) {
        assert(ans[i] != -1);
        if(ans[i]) cout << '('; 
        else cout << ')';
    }
}

Compilation message

zagrade.cpp: In function 'int main()':
zagrade.cpp:48:21: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |         if(s.size() >= x) ok = 1;
      |            ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 4 ms 208 KB Output is correct
3 Correct 8 ms 208 KB Output is correct
4 Correct 8 ms 208 KB Output is correct
5 Correct 11 ms 208 KB Output is correct
6 Correct 9 ms 320 KB Output is correct
7 Correct 8 ms 336 KB Output is correct
8 Correct 8 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 12 ms 348 KB Output is correct
3 Correct 8 ms 324 KB Output is correct
4 Correct 8 ms 324 KB Output is correct
5 Correct 7 ms 320 KB Output is correct
6 Correct 9 ms 328 KB Output is correct
7 Correct 12 ms 324 KB Output is correct
8 Correct 4 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 389 ms 696 KB Output is correct
3 Correct 848 ms 720 KB Output is correct
4 Correct 810 ms 696 KB Output is correct
5 Correct 726 ms 720 KB Output is correct
6 Correct 832 ms 720 KB Output is correct
7 Correct 841 ms 3148 KB Output is correct
8 Correct 727 ms 704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 851 ms 5532 KB Output is correct
3 Correct 703 ms 1632 KB Output is correct
4 Correct 882 ms 3076 KB Output is correct
5 Correct 862 ms 1620 KB Output is correct
6 Correct 745 ms 3160 KB Output is correct
7 Correct 803 ms 2248 KB Output is correct
8 Correct 752 ms 720 KB Output is correct