Submission #7268233


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

const int N = 1005;

int n;
int a[N][N];
int idx[N];

bool waiting[N][N];

int main() {
  scanf("%d", &n);
  
  vector<int> toCheck;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n-1; ++j) {
      scanf("%d", &a[i][j]);
      --a[i][j];
    }
    idx[i] = 0;
    toCheck.push_back(i);
  }
  
  int day = 0;
  bool can = true;
  while (can) {
    can = false;
    
    vector<int> ncheck;
    for (int u: toCheck) {
      int v = a[u][idx[u]];
      if (v < u) swap(u, v);
      
      if (waiting[u][v]) {
        can = true;
        waiting[u][v] = false;
        
        ++idx[u], ++idx[v];
        if (idx[u] < n-1) ncheck.push_back(u);
        if (idx[v] < n-1) ncheck.push_back(v);
      } else {
        waiting[u][v] = true;
      }
    }

    toCheck = ncheck;
    if (can) ++day;
  }
  
  for (int i = 0; i < n; ++i) {
    if (idx[i] != n-1) day = -1;
  }
  
  printf("%d\n", day);
  return 0;
}

Submission Info

Submission Time
Task E - League
User prabowo
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1020 Byte
Status AC
Exec Time 138 ms
Memory 5120 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:13:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
./Main.cpp:18:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &a[i][j]);
                            ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 23
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 AC 138 ms 5120 KB
b09 AC 84 ms 4992 KB
b10 AC 113 ms 5120 KB
b11 AC 117 ms 5120 KB
b12 AC 32 ms 3840 KB
b13 AC 27 ms 3840 KB
b14 AC 14 ms 3712 KB
b15 AC 11 ms 3584 KB
b16 AC 7 ms 1408 KB
b17 AC 5 ms 1152 KB
b18 AC 23 ms 3712 KB
b19 AC 19 ms 3712 KB
b20 AC 7 ms 1408 KB
b21 AC 6 ms 1152 KB
b22 AC 3 ms 896 KB
b23 AC 2 ms 640 KB