답안 #210947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210947 2020-03-19T03:22:45 Z ryansee DEL13 (info1cup18_del13) C++14
0 / 100
7 ms 1152 KB
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
bool state[MAXN];
void solve(){
	mmst(state,0);
	ll n,q;cin>>n>>q;
	FOR(i,0,q-1){
		ll a; cin>>a;
		state[a]=1;
	}
	vector<ll> comp;
	auto gogo=[&](){
		if(comp.empty())return 1;
		vector<ll> tmp=comp;
		FOR(i,0,siz(comp)-2){
			if(comp[i]==0)continue;
			ll hmm,used=tmp[i]-comp[i];
			if(used==0) hmm=(comp[i]-1)/2;
			else hmm=(tmp[i]-used)/2;
			comp[i]-=hmm*2;
			comp[i+1]-=comp[i];
			comp[i]=0;
			if(comp[i+1]<0){
				cout<<"-1\n";
				return 0;
			}
		}
		ll hmm,used=tmp.back()-comp.back();
		if(used==0) hmm=(comp.back()-1)/2;
		else hmm=(tmp.back()-used)/2;
		comp.back()-=hmm*2;
		if(comp.back()){
			cout<<"-1\n";
			return 0;
		}
		return 1;
	};
	FOR(i,1,n){
		if(state[i]==0){
			if(i>1&&state[i-1]==0) {
				++ comp.back();
			}else{
				comp.pb(1);
			}
		}else{
			if(i>1&&state[i-1]==1){
				assert(!gogo());
				return;
				comp.clear();
			}
		}
	}
	assert(!gogo());
	return;
	cout<<0<<'\n'<<'\n';
}
int main(){
	FAST
	ll t; cin>>t;
	while(t--)solve();
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 5 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 5 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 7 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 5 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 5 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 5 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 5 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 5 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 6 ms 1152 KB Execution killed with signal 11 (could be triggered by violating memory limits)