Submission #7267440


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;
      }
    }

    ncheck = toCheck;
    ++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 0
Code Size 1011 Byte
Status RE
Exec Time 344 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 0 / 500
Status
AC × 2
WA × 1
AC × 5
WA × 3
RE × 15
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 WA 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 RE 144 ms 256 KB
b06 WA 1 ms 256 KB
b07 AC 1 ms 256 KB
b08 RE 307 ms 5120 KB
b09 AC 83 ms 4992 KB
b10 WA 103 ms 5120 KB
b11 RE 344 ms 5120 KB
b12 RE 159 ms 3840 KB
b13 RE 152 ms 3840 KB
b14 RE 129 ms 3712 KB
b15 RE 124 ms 3584 KB
b16 RE 119 ms 1408 KB
b17 RE 115 ms 1024 KB
b18 RE 142 ms 3712 KB
b19 RE 141 ms 3712 KB
b20 RE 121 ms 1408 KB
b21 RE 118 ms 1152 KB
b22 RE 116 ms 896 KB
b23 RE 111 ms 640 KB