답안 #67297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67297 2018-08-13T19:54:43 Z ekrem DEL13 (info1cup18_del13) C++
0 / 100
500 ms 14676 KB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int t, n, q, m, b[N], a[N], dp[3][N];

bool f(int sol, int ind){
	int &r = dp[sol][ind];
	if(r != -1)
		return r;
	if(ind > m and sol == 0)
		return 1;
	if(sol > a[ind])
		return 0;
	int yeni = a[ind] - sol;
	bool don = 0;
	int md = a[ind]%2;
	if(a[ind] > 0 and !md)
		md = 2;
	if(sol == md)
		don |= f(0, ind + 1);
	// cout << a[ind] << " -> " << sol  << " = " << yeni << " , " << md<< endl;
	for(int i = 1; i <= 2; i++){
		if(yeni >= i and (yeni - i)%2 == 0)
			don |= f(i, ind + 1);
	}
	return r = don;
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d",&t);
	while(t--){
		memset(dp, -1, sizeof dp);
		m = 0;
		int top = 0;
		scanf("%d %d",&n ,&q);
		for(int i = 1; i <= q; i++)
			scanf("%d", b + i);
		b[q + 1] = n + 1;
		for(int i = 1; i <= q + 1; i++)
			top += a[++m] = b[i] - b[i - 1] - 1;
		// for(int i = 1; i <= m; i++)cout << a[i] << " ";cout << endl;
		if(!f(0, 1))
			printf("-1\n");
		else
			printf("%d\n",top/2);
	}
	return 0;
}

Compilation message

del13.cpp: In function 'bool f(int, int)':
del13.cpp:31:11: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  return r = don;
         ~~^~~~~
del13.cpp: In function 'int main()':
del13.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&t);
  ~~~~~^~~~~~~~~
del13.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&n ,&q);
   ~~~~~^~~~~~~~~~~~~~~~
del13.cpp:44:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", b + i);
    ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 343 ms 12152 KB Integer -1 violates the range [1, 9]
2 Incorrect 343 ms 12264 KB Integer -1 violates the range [1, 8]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 343 ms 12152 KB Integer -1 violates the range [1, 9]
2 Incorrect 343 ms 12264 KB Integer -1 violates the range [1, 8]
3 Execution timed out 1076 ms 12264 KB Time limit exceeded
4 Execution timed out 1068 ms 12264 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Incorrect 490 ms 12368 KB Integer -1 violates the range [1, 28]
2 Incorrect 156 ms 12420 KB Integer -1 violates the range [1, 5]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 343 ms 12152 KB Integer -1 violates the range [1, 9]
2 Incorrect 343 ms 12264 KB Integer -1 violates the range [1, 8]
3 Execution timed out 1076 ms 12264 KB Time limit exceeded
4 Execution timed out 1068 ms 12264 KB Time limit exceeded
5 Incorrect 77 ms 12420 KB Integer -1 violates the range [1, 100]
6 Incorrect 62 ms 12420 KB Integer -1 violates the range [1, 100]
7 Incorrect 60 ms 12420 KB Integer -1 violates the range [1, 53]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 343 ms 12152 KB Integer -1 violates the range [1, 9]
2 Incorrect 343 ms 12264 KB Integer -1 violates the range [1, 8]
3 Execution timed out 1076 ms 12264 KB Time limit exceeded
4 Execution timed out 1068 ms 12264 KB Time limit exceeded
5 Incorrect 77 ms 12420 KB Integer -1 violates the range [1, 100]
6 Incorrect 62 ms 12420 KB Integer -1 violates the range [1, 100]
7 Incorrect 60 ms 12420 KB Integer -1 violates the range [1, 53]
8 Incorrect 92 ms 12604 KB Integer -1 violates the range [1, 87]
9 Incorrect 88 ms 13344 KB Integer -1 violates the range [1, 94]
10 Incorrect 95 ms 13500 KB Integer 124 violates the range [1, 99]
11 Incorrect 89 ms 14676 KB Integer -1 violates the range [1, 81]