제출 #40069

#제출 시각아이디문제언어결과실행 시간메모리
40069krauchDijamant (COI16_dijament)C++14
100 / 100
377 ms3320 KiB
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

*/
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair < ll, int > PLI;


#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

#define fname ""

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e3 + 6;

int n, sz;
bitset < N > par[N], bad[N];
map < string, int > mp;

int main() {
	ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

	#ifdef krauch
        freopen("input.txt", "r", stdin);
    #else
        //freopen(fname".in", "r", stdin);
        //freopen(fname".out", "w", stdout);
    #endif

    cin >> n;
    forn(i, 1, n) {
        string s;
        getline(cin, s);
        if (i == 1) getline(cin, s);

        int ptr = 0;
        string vname = "";
        bool fu = 0;
        while (s[ptr] != ' ') {
            vname += s[ptr];
            ++ptr;
        }
        ptr += 3;
        if (mp.count(vname)) fu = 1;

        vector < int > tmp;
        string toname = "";
        while (s[ptr] != ';') {
            if (s[ptr] == ' ') {
                if (!mp.count(toname)) fu = 1;
                else tmp.eb(mp[toname]);
                toname = "";
            }
            else {
                toname += s[ptr];
            }
            ++ptr;
        }

        if (fu) {
            cout << "greska\n";
            continue;
        }

        bitset < N > bit;
        for (auto it : tmp) {
            bit |= par[it];
        }
        forn(i, 1, sz) {
            if (!bit[i]) continue;
            if ((bad[i] & bit).count()) fu = 1;
        }
        if (fu) {
            cout << "greska\n";
            continue;
        }
        ++sz;
        mp[vname] = sz;
        par[sz] = bit;
        par[sz][sz] = 1;
        forn(i, 1, sz) {
            if (par[sz][i]) continue;
            if ((par[sz] & par[i]).count()) bad[sz][i] = 1;
        }
        cout << "ok\n";
    }

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...