Submission #672399

# Submission time Handle Problem Language Result Execution time Memory
672399 2022-12-16T01:28:18 Z horiseun Zagrade (COI20_zagrade) C++11
Compilation error
0 ms 0 KB
#include <iostream>
#include <stack>
#include <cstring>
using namespace std;

stack<int> unpaired;
char s[100005];
int count;

string solve(int n, int q) {
    unpaired.push(0);
    for (int i = 1; i < n; i++) {
        if (unpaired.empty()) {
            unpaired.push(i);
            continue;
        }
        if (query(unpaired.top(), i)) {
            s[unpaired.top()] = '(';
            s[i] = ')';
            unpaired.pop();
        } else {
            unpaired.push(i);
        }
    }

    for (int i = 0; i < n; i++) {
        if (!(s[i] == ')' || s[i] == '(')) count++;
    }
    count /= 2;

    string ans = "";
    for (int i = 0; i < n; i++) {
        if (s[i] == ')' || s[i] == '(') {
            ans += s[i];
        } else {
            if (count) {
                ans += ')';
                count--;
            } else {
                ans += '(';
            }
        }
    }

    return ans;

}

Compilation message

zagrade.cpp: In function 'std::string solve(int, int)':
zagrade.cpp:17:13: error: 'query' was not declared in this scope
   17 |         if (query(unpaired.top(), i)) {
      |             ^~~~~