답안 #201199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201199 2020-02-09T18:46:00 Z Ort Političari (COCI20_politicari) C++11
70 / 70
26 ms 1400 KB
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int n;
ll k;

int mt[505][505];

set<pair<int,int> > C;
vector<int> p, R;

int main() {
	
	ios_base::sync_with_stdio(0); 
	cin.tie(0); cout.tie(0);
	
	cin >> n >> k;
	
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin >> mt[i][j];
	
	p.push_back(1);
	int start = 2;
	int next = 0;
	
	while(true) {
		if(C.count(make_pair(p.back(), start))) break;
		C.insert(make_pair(p.back(), start));
		next = mt[start][p.back()];
		p.push_back(start);
		start = next;
	}
	
	
	int fst = 1;
	
	for(int i=0;i<p.size()-1;i++) {
		if(p[i+1]==next && p[i]==p.back()) break;
		fst++;
	}
	
	for(int i=fst;i<p.size();i++) R.push_back(p[i]);
	
	if(k==1) cout << 1;
	else if(k==2) cout << 2;
	else {
		if(k<=fst) {
			cout << p[k];
			return 0;
		}
		k -= fst; k--;
		int md = R.size();
		cout << R[k%md];
	}
	
	return 0;
}

Compilation message

politicari.cpp: In function 'int main()':
politicari.cpp:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<p.size()-1;i++) {
              ~^~~~~~~~~~~
politicari.cpp:45:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=fst;i<p.size();i++) R.push_back(p[i]);
                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 9 ms 888 KB Output is correct
3 Correct 18 ms 1144 KB Output is correct
4 Correct 22 ms 1272 KB Output is correct
5 Correct 26 ms 1400 KB Output is correct
6 Correct 25 ms 1272 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 636 KB Output is correct
9 Correct 9 ms 888 KB Output is correct
10 Correct 22 ms 1272 KB Output is correct
11 Correct 26 ms 1400 KB Output is correct
12 Correct 25 ms 1400 KB Output is correct
13 Correct 5 ms 504 KB Output is correct
14 Correct 6 ms 632 KB Output is correct