답안 #200978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
200978 2020-02-09T02:27:13 Z model_code Političari (COCI20_politicari) C++17
70 / 70
39 ms 2168 KB
#include <bits/stdc++.h>

using namespace std;

#define TRACE(x) cerr << #x << " " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<

typedef long long llint;

const int MAXN = 505;

int n;
int mat[MAXN][MAXN], bio[MAXN][MAXN], guest[MAXN * MAXN];

llint k;

int main(void) {
  scanf("%d%lld", &n, &k);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      scanf("%d", &mat[i][j]);
      --mat[i][j];
    }
  }

  int prev = 0, curr = 1;
  guest[1] = 0;
  guest[2] = 1;
  bio[prev][curr] = 2;
  for (int i = 3; (llint) i <= k; ++i) {
    int nxt = mat[curr][prev];
    prev = curr;
    curr = nxt;
    if (bio[prev][curr] == 0) {
      bio[prev][curr] = i;
      guest[i] = curr;
      continue;
    }
    int j = bio[prev][curr];
    int cycle = i - j;
    int ret = j + ((k - j) % cycle);
    printf("%d\n", guest[ret] + 1);
    return 0;
  }

  printf("%d\n", guest[k] + 1);
  return 0;
}

Compilation message

politicari.cpp: In function 'int main()':
politicari.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld", &n, &k);
   ~~~~~^~~~~~~~~~~~~~~~~~
politicari.cpp:23:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &mat[i][j]);
       ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 11 ms 1272 KB Output is correct
3 Correct 26 ms 1784 KB Output is correct
4 Correct 33 ms 1912 KB Output is correct
5 Correct 39 ms 2040 KB Output is correct
6 Correct 39 ms 1912 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 7 ms 888 KB Output is correct
9 Correct 12 ms 1272 KB Output is correct
10 Correct 32 ms 1784 KB Output is correct
11 Correct 38 ms 2168 KB Output is correct
12 Correct 38 ms 2040 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 9 ms 888 KB Output is correct