답안 #744527

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
744527 2023-05-18T16:50:48 Z nvujica Dijamant (COI16_dijament) C++14
100 / 100
250 ms 4744 KB
#include <bits/stdc++.h>

#define ll long long
#define fi first
#define se second

using namespace std;

const int maxn = 1010;

int n, cnt;
bool ok;
map <string, int> mp;
int d[maxn];
int bio[maxn];
vector <int> par[maxn];

void rek(int x, int br){
	if(bio[x] && bio[x] != br){
		ok = 0;
		return;
	}
	
	bio[x] = br;
	
	for(int i = 0; i < par[x].size(); i++){
		rek(par[x][i], br);
		if(!ok) return;
	}
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	
	for(int j = 0; j < n; j++){
		string k, p;
		cin >> k;
		cin >> p;
		
		ok = 1;
		
		if(mp[k]) ok = 0;
		
		vector <pair<int, int> > v;
		
		while(true){
			cin >> p;
			
			if(p == ";") break;
			
			if(!mp[p]) ok = 0;
			else {
				v.push_back({d[mp[p]], mp[p]});
			}
		}
		
		if(!ok){
			cout << "greska\n";
			continue;
		}
		
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());
		
		memset(bio, 0, sizeof bio);
		
		for(int i = 0; i < v.size(); i++){
			int x = v[i].se;
			
			if(!bio[x]) rek(x, x);
		}
		
		if(!ok){
			cout << "greska\n";
			continue;
		}
		
		cout << "ok\n";
		
		cnt++;
		mp[k] = cnt;
		
		if(!v.empty()) d[cnt] = v[0].fi + 1;
		
		for(int i = 0; i < v.size(); i++){
			if(bio[v[i].se] == v[i].se) par[cnt].push_back(v[i].se);
		}
	}
	
	return 0;
}

Compilation message

dijament.cpp: In function 'void rek(int, int)':
dijament.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(int i = 0; i < par[x].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~
dijament.cpp: In function 'int main()':
dijament.cpp:70:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |   for(int i = 0; i < v.size(); i++){
      |                  ~~^~~~~~~~~~
dijament.cpp:88:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   for(int i = 0; i < v.size(); i++){
      |                  ~~^~~~~~~~~~
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 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 340 KB Output is correct
# 결과 실행 시간 메모리 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 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 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 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 400 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 340 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 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 212 ms 404 KB Output is correct
2 Correct 250 ms 4744 KB Output is correct
3 Correct 133 ms 4624 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 6 ms 468 KB Output is correct
7 Correct 14 ms 624 KB Output is correct
8 Correct 24 ms 788 KB Output is correct
9 Correct 25 ms 724 KB Output is correct
10 Correct 6 ms 488 KB Output is correct
11 Correct 7 ms 480 KB Output is correct
12 Correct 212 ms 3752 KB Output is correct