제출 #1174573

#제출 시각아이디문제언어결과실행 시간메모리
1174573browntoadDEL13 (info1cup18_del13)C++20
6 / 100
3 ms1476 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long // #define int ll #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define REP1(i, n) FOR(i, 1, n+1) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define pii pair<int, int> #define pip pair<int, pii> #define f first #define s second #define pb push_back #define ALL(x) (x).begin(), (x).end() #define SZ(x) (int)((x).size()) #define endl '\n' #ifdef TOAD #define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #else #define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) #endif // TOAD const ll maxn = 1e3+5; const int iinf = 1e9+5; signed main(){ IOS(); int t; cin>>t; while(t--){ int n, q; cin>>n>>q; vector<bool> toad(n+1); vector<int> rem(q), del; REP(i, q){ cin>>rem[i]; toad[rem[i]] = 1; } REP1(i, n){ if (!toad[i]) del.pb(i); } vector<vector<int>> nip; int pre = -3; for (auto x:del){ if (x-pre > 2){ vector<int> poo; poo.pb(x); nip.pb(poo); } else nip.back().pb(x); pre = x; } bool gg = false; for (auto vv:nip){ if (SZ(vv)&1) gg = 1; bool ex = 0; REP(i, SZ(vv)-1) if (vv[i+1] > vv[i]+1) ex = 1; if (!ex) gg = 1; int cnt = 0; vector<int> oo; REP(i, SZ(vv)){ cnt++; if (i == SZ(vv)-1 || vv[i+1] != vv[i]+1){ oo.pb(cnt); cnt = 0; } } REP(i, SZ(oo)-1){ if (oo[i] <= 0){ gg = 1; break; } if (oo[i]&1){ oo[i+1]--; } else oo[i+1] -= 2; } if (oo.back() < 0){ gg = 1; break; } if (gg) break; } cout<<(gg?-1:0)<<endl; } } /* 2 3 2 4 3 5 7 5 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...