# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
197297 | 2020-01-20T08:52:16 Z | Redhood | DEL13 (info1cup18_del13) | C++14 | 34 ms | 952 KB |
#include<bits/stdc++.h> #define fi first #define se second #define pb push_back #define len(x) (int)(x).size() typedef long long ll; typedef long double ld; using namespace std; vector<int> solve(vector<int>nums){ if(len(nums)==1)return{}; // for(auto i : nums)cout << i << ' '; // cout << endl << endl; vector < int > main; vector<int>seg; for(int i = 1; i < len(nums);++i){ seg.pb(nums[i]-nums[i-1]-1); } bool sum = 0; for(auto u : seg)sum ^= (u&1); if(sum)return {-1}; /// firstly close all 1 vector < bool > done(len(seg)); for(int i = 0 ; i < len(seg) - 1;++i){ if(seg[i]&1){ main.pb(nums[i + 1]); done[i] = 1; done[i + 1] = 1; seg[i]--; seg[i + 1]--; } } // cout << " SEGS \n"; // for(auto i : seg)cout << i << ' '; // cout << "\n DONE\n"; // for(int i = 0 ; i < len(seg);++i)cout << done[i]; // // cout << endl << endl; vector < bool > dp(len(seg) + 1); vector < int > pred(len(seg) + 1); dp[0] = 1; if(done[0])dp[1]=1 , pred[1] = 0; for(int i = 2; i <= len(seg);++i){ if((done[i - 1]||seg[i-1]) && dp[i - 1]){ dp[i] = 1; pred[i] = 0; continue; } if((seg[i-1]>=2)&&(seg[i-2]>=4)&&dp[i-1]){ dp[i] = 1; pred[i] = 1; } if((seg[i-1]>=2)&&(seg[i-2]>=2)&&dp[i-2]){ dp[i] = 1; pred[i] = 2; } } if(!dp[len(seg)])return {-1}; int curr = len(seg); while(curr > 0){ // cout << " CURR " << curr << '\n'; if(pred[curr]==0){ curr--; continue; } main.pb(nums[curr-1]); main.pb(nums[curr-1]); seg[curr-1]-=2; seg[curr-2]-=2; if(pred[curr]==1){ curr--; }else { curr -= 2; } } vector < int > extra; for(int i = 0; i < len(nums) - 1; ++i){ // assert(seg[i] >= 0); int pos = nums[i] + (nums[i+1]-nums[i]-1 + 1) / 2; while(seg[i] > 0){ extra.pb(pos); seg[i] -= 2; } } // for(int i = 0 ; i < len(nums) - 1; ++i) // assert(seg[i]==0); vector < int > answer; // cout << " MAIN : \n"; // for(auto u : main)cout << u << endl; // cout << endl; for(auto u : extra)answer.pb(u); for(auto u : main)answer.pb(u); return answer; } signed main(){ int t; cin >> t; while(t--){ int n , q; cin >> n >> q; vector < int > pos(q); for(auto &i : pos)cin >> i; pos.insert(pos.begin() , 0); pos.pb(n+1); int sum = 0; vector < int > nums; int prev = 0; vector<int>answer; nums.pb(0); for(int i = 1; i < len(pos); ++i){ if(pos[i-1]+1==pos[i]){ vector<int>ans=solve(nums); // cout << endl; // for(auto &u : nums)cout << u << ' ' ; // cout << " ANS " << len(ans) << endl; for(auto u : ans)answer.pb(u); nums.clear(); } nums.pb(pos[i]); } if(len(nums)>1){ vector<int>ans=solve(nums); for(auto u : ans)answer.pb(u); } bool cant = 0; for(auto &i : answer){ if(i == -1){ cout<<-1<<'\n'; cant = 1; break; } } if(!cant){ if(len(answer) >= 0){ cout << 0 << '\n'; cout << '\n'; } // cout << len(answer) << '\n'; // for(auto &i : answer)cout << i << ' '; // cout << '\n'; } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 256 KB | Output isn't correct |
2 | Incorrect | 5 ms | 376 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 256 KB | Output isn't correct |
2 | Incorrect | 5 ms | 376 KB | Output isn't correct |
3 | Incorrect | 20 ms | 360 KB | Output isn't correct |
4 | Incorrect | 21 ms | 256 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 376 KB | Output is partially correct |
2 | Correct | 8 ms | 376 KB | Output is partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 256 KB | Output isn't correct |
2 | Incorrect | 5 ms | 376 KB | Output isn't correct |
3 | Incorrect | 20 ms | 360 KB | Output isn't correct |
4 | Incorrect | 21 ms | 256 KB | Output isn't correct |
5 | Correct | 4 ms | 376 KB | Output is partially correct |
6 | Correct | 4 ms | 376 KB | Output is partially correct |
7 | Correct | 4 ms | 376 KB | Output is partially correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 256 KB | Output isn't correct |
2 | Incorrect | 5 ms | 376 KB | Output isn't correct |
3 | Incorrect | 20 ms | 360 KB | Output isn't correct |
4 | Incorrect | 21 ms | 256 KB | Output isn't correct |
5 | Correct | 4 ms | 376 KB | Output is partially correct |
6 | Correct | 4 ms | 376 KB | Output is partially correct |
7 | Correct | 4 ms | 376 KB | Output is partially correct |
8 | Correct | 29 ms | 376 KB | Output is partially correct |
9 | Correct | 34 ms | 492 KB | Output is partially correct |
10 | Correct | 31 ms | 536 KB | Output is partially correct |
11 | Correct | 33 ms | 952 KB | Output is partially correct |