Submission #768771

# Submission time Handle Problem Language Result Execution time Memory
768771 2023-06-28T15:03:47 Z MetalPower Dijamant (COI16_dijament) C++14
100 / 100
260 ms 4584 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define fi first
#define se second

const int MX = 1e3 + 10;
const int INF = 1e9 + 7;

int N, tim = 0; int src[MX]; bool f = true;
map<string, int> mp;
vector<int> adj[MX];

void dfs(int u){
	for(int nx : adj[u]){
		if(src[nx] == 0){
			src[nx] = u;
			dfs(nx);
		}else if(src[nx] != u){
			f = false;
		}
	}
}

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

	cin >> N;
	for(int x = 0; x < N; x++){

		string s, tmp; vector<string> nx;
		cin >> s >> tmp >> tmp;

		for(; tmp != ";"; ){
			nx.push_back(tmp);
			cin >> tmp;
		}

		f = true;

		if(f) { // First rule #1 : s must not be declared before
			if(mp[s] != 0) f = false;
		}

		if(f) { // Second rule #2 : all in nx must already be declared before
			for(string st : nx){
				if(mp[st] == 0){
					f = false;
					break;
				}
			}
		}

		if(f) { // Third rule #3 : no diamonds
			for(int i = 0; i <= tim; i++) src[i] = 0;
			for(string st : nx){
				if(f) 
					dfs(mp[st]);
			}
		}

		if(f) {
			mp[s] = ++tim;
			for(string st : nx){ // if the node is in a line only enter the last one
				if(src[mp[st]] == 0) adj[tim].push_back(mp[st]);
			}
		}

		if(f) cout << "ok\n";
		else cout << "greska\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 352 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 197 ms 4108 KB Output is correct
2 Correct 260 ms 4584 KB Output is correct
3 Correct 48 ms 4552 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 4 ms 464 KB Output is correct
7 Correct 6 ms 612 KB Output is correct
8 Correct 10 ms 724 KB Output is correct
9 Correct 11 ms 820 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 464 KB Output is correct
12 Correct 201 ms 3856 KB Output is correct