Submission #666840

# Submission time Handle Problem Language Result Execution time Memory
666840 2022-11-29T19:33:57 Z LFFB Superpozicija (COCI22_superpozicija) C++14
0 / 110
31 ms 1108 KB
#include <iostream>

const int MAX_N = 1e5 + 10;

template<typename T>
class SpecialVector {
private:
    T* values;
    T standard;
    int* lastChanged;
    int time;
public:
    SpecialVector(int size, T s) {
        values = new T[size];
        lastChanged = new int[size];
        standard = s;
        time = 1;
    }
    T& operator[](int i) {
        if (lastChanged[i] != time) {
            lastChanged[i] = time;
            values[i] = standard;
        }
        return values[i];
    }
    void clear() {
        time++;
    }
};

int n, t;

SpecialVector<char> str(2*MAX_N, ' ');
SpecialVector<char> str2(2*MAX_N, ' ');
SpecialVector<std::pair<int, int>> pairs(MAX_N, {0, 0});

int main() {
    scanf("%d", &t);
    for (int test = 0; test < t; test++) {

        str.clear();
        pairs.clear();

        scanf("%d", &n);

        int count1 = 0;
        int count2 = 0;

        for (int i = 0; i < 2*n; i++) {
            char c;
            scanf(" %c ", &c);
            str[i] = c;
            if (c == '(') count1++;
            if (c == ')') count2++;
        }

        for (int i = 0; i < n; i++) {
            int a, b;
            scanf("%d %d", &a, &b);
            a--; b--;
            pairs[i] = {a, b};
        }

        for (int i = 0; i < n; i++) {

            int a = pairs[i].first;
            int b = pairs[i].second;
            char c = str[a];

            if (c == '(') str2[std::min(a, b)] = c;
            if (c == ')') str2[std::max(a, b)] = c;

        }

        int verify = 0;
        bool valid = true;
        for (int i = 0; i < 2*n; i++) {
            if (str2[i] == '(') {
                verify++;
            } else if (str2[i] == ')') {
                verify--;
                if (verify < 0) valid = false;
            }
        }
        if (verify != 0) valid = false;
        if (!valid) {
            printf("-1\n");
            continue;
        }

        for (int i = 0; i < n; i++) {

            int a = pairs[i].first;
            int b = pairs[i].second;
            char c = str[a];

            if (c == '(') {
                printf("%d", a < b ? 0 : 1);
            } else {
                printf("%d", a < b ? 1 : 0);
            }
            if (i != n - 1) printf(" ");
        }
        printf("\n");

    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     scanf("%d", &t);
      |     ~~~~~^~~~~~~~~~
Main.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
Main.cpp:52:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |             scanf(" %c ", &c);
      |             ~~~~~^~~~~~~~~~~~
Main.cpp:60:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |             scanf("%d %d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -