답안 #637101

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
637101 2022-08-31T14:11:21 Z Dec0Dedd DEL13 (info1cup18_del13) C++14
6 / 100
16 ms 6472 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+10;
int d[N], rm[N], par[N][4], n, q;
bool dp[N][4], vis[N][4];

bool gen(int i, int l) {
   int x=d[i]-l;
   if (x < 0) return false;
   if (i == q) {
      if (l == 0) return true;
      return false;
   }

   if (vis[i][l]) return dp[i][l];
   vis[i][l]=true;

   if (x%2 == 0) {
      if ((x == 0 || l > 0) && gen(i+1, 0)) par[i][l]=0, dp[i][l]=true;
      if (x >= 2 && gen(i+1, 2)) par[i][l]=2, dp[i][l]=true;
   } else {
      if (gen(i+1, 1)) par[i][l]=1, dp[i][l]=true;
   }

   return dp[i][l];
}

void solve() {
   cin>>n>>q;

   if (q == 0) {
      cout<<0<<"\n";
      return;
   }

   for (int i=0; i<=n; ++i) d[i]=rm[i]=0;
   for (int i=0; i<=n; ++i) {
      for (int j=0; j<5; ++j) dp[i][j]=vis[i][j]=false, par[i][j]=-1;
   }

   vector<int> v;
   v.push_back(0);
   for (int i=0; i<q; ++i) {
      int p; cin>>p;
      v.push_back(p);
   }
   q+=2, v.push_back(n+1);
   for (int i=1; i<q; ++i) d[i]=v[i]-v[i-1]-1;
   bool ok=gen(1, 0);

   if (!ok) {
      cout<<-1<<"\n";
   } else {
      cout<<0<<"\n";
      cout<<"\n";
   }
}

int main() {
   int t; cin>>t;
   while (t--) solve();
}

Compilation message

del13.cpp: In function 'void solve()':
del13.cpp:40:49: warning: iteration 4 invokes undefined behavior [-Waggressive-loop-optimizations]
   40 |       for (int j=0; j<5; ++j) dp[i][j]=vis[i][j]=false, par[i][j]=-1;
      |                                        ~~~~~~~~~^~~~~~
del13.cpp:40:22: note: within this loop
   40 |       for (int j=0; j<5; ++j) dp[i][j]=vis[i][j]=false, par[i][j]=-1;
      |                     ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Incorrect 2 ms 212 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Incorrect 2 ms 212 KB Output isn't correct
3 Correct 8 ms 340 KB Output is partially correct
4 Correct 8 ms 340 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 468 KB Output is partially correct
2 Correct 4 ms 3028 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Incorrect 2 ms 212 KB Output isn't correct
3 Correct 8 ms 340 KB Output is partially correct
4 Correct 8 ms 340 KB Output is partially correct
5 Correct 2 ms 340 KB Output is partially correct
6 Incorrect 2 ms 340 KB Output isn't correct
7 Incorrect 2 ms 340 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Incorrect 2 ms 212 KB Output isn't correct
3 Correct 8 ms 340 KB Output is partially correct
4 Correct 8 ms 340 KB Output is partially correct
5 Correct 2 ms 340 KB Output is partially correct
6 Incorrect 2 ms 340 KB Output isn't correct
7 Incorrect 2 ms 340 KB Output isn't correct
8 Correct 14 ms 3796 KB Output is partially correct
9 Correct 16 ms 4916 KB Output is partially correct
10 Correct 16 ms 5092 KB Output is partially correct
11 Correct 16 ms 6472 KB Output is partially correct