Submission #963457

#TimeUsernameProblemLanguageResultExecution timeMemory
963457riaritiDijamant (COI16_dijament)C++17
100 / 100
1597 ms4724 KiB
#include <bits/stdc++.h>

namespace MX {

constexpr int N = 1E3 + 9;

}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int N;
    std::cin >> N;

    std::map<std::string, int> cc;
    std::vector anc(N, std::bitset<MX::N>(0));
    for (int k = 0; k < N; k++) {
        std::string K;
        std::cin >> K;

        bool bad = cc.count(K);

        std::vector<int> P;

        std::string s;
        std::cin >> s;
        while (true) {
            std::cin >> s;
            if (s == ";") {
                break;
            }

            if (!cc.count(s)) {
                bad = true;
                continue;
            }

            auto v = cc[s];
            P.push_back(v);

            anc[k] |= anc[v];
            anc[k][v] = true;
        }

        for (int i = 0; i < P.size() && !bad; i++) {
            for (int j = i + 1; j < P.size() && !bad; j++) {
                auto u = P[i];
                auto v = P[j];

                auto f = anc[u] & anc[v];
                if (f.any()) {
                    bad |= !(anc[u][v] || anc[v][u]);
                }
            }
        }

        if (bad) {
            std::cout << "greska\n";
            continue;
        }

        std::cout << "ok\n";
        cc[K] = k;
    }

    return 0;
}

Compilation message (stderr)

dijament.cpp: In function 'int main()':
dijament.cpp:46:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for (int i = 0; i < P.size() && !bad; i++) {
      |                         ~~^~~~~~~~~~
dijament.cpp:47:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             for (int j = i + 1; j < P.size() && !bad; j++) {
      |                                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...