Submission #317122

# Submission time Handle Problem Language Result Execution time Memory
317122 2020-10-29T03:48:05 Z Kevin_Zhang_TW DEL13 (info1cup18_del13) C++17
0 / 100
13 ms 1984 KB
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] : ", args)
void kout() { cerr << endl; }
template<class T, class ...U>
void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
void debug(auto L, auto R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
#else
#define debug(...) 0
#define DE(...) 0
#endif
const int MAX_N = 300010, inf = 1e7;
int len, m, p[MAX_N], dp_max[MAX_N], dp_min[MAX_N], dis[MAX_N];
bool valid() {
	DE(len, m);
	if ((len ^ m++) & 1)
		return false;
	for (int i = 1;i <= m;++i)
		dis[i] = p[i] - p[i-1] - 1;

	dp_max[0] = dp_min[0] = 0;
	DE(len, m);
	debug(dis+1, dis+m+1);
	for (int i = 1;i <= m;++i) {
		int u = dp_max[i-1], d = dp_min[i-1], h = dis[i];
		if (d > h)
			return false;

		if (h == 0) {
			dp_max[i] = dp_min[i] = 0;
			continue;
		}
		if (u == 0) {
			dp_max[i] = h, dp_min[i] = h&1 ? 1 : 2;
			continue;
		}
		dp_max[i] = h - d;
		if (h % 2 == d % 2) 
			dp_min[i] = 0;
		else 
			dp_min[i] = 1;

		if (dp_max[i] < dp_min[i])
			return false;
	}
	for (int i = 1;i <= m;++i) 
		DE(i, dp_min[i], dp_max[i]);
	if (dp_min[m] != 0)
		return false;

	int need = (len - (m-1)) / 2;
	cout << need  << '\n';

	vector<int> cnt(m+2), self(m+2);
	int tar_h = 0, nxt_h, cur_h = dis[m] ;
	for (int i = m;i >= 1;--i) {
		int u = dp_max[i-1], d = dp_min[i-1], h = dis[i];

		int rm = cur_h - tar_h, mxcon = min(dis[i-1] - dp_min[i-1], rm);
		
		cnt[i] = mxcon;

		cur_h = dis[i-1] - mxcon;
	}
	for (int i = 1;i <= m;++i) {
		int lft = dis[i] - cnt[i] - cnt[i+1];
		//assert(lft % 2 == 0);
		self[i] = lft / 2;
	}
	vector<int> op;
	for (int i = 1;i <= m;++i) 
		while (self[i]--)
			op.pb(p[i]-2);

	for (int i = 1;i <= m;++i)
		while (cnt[i]--)
			op.pb(p[i-1]);

	op.resize(need);
	//assert(need == op.size());

	for (int i = 0;i < need;++i)
		cout << op[i] << " \n"[i+1==need];
		

	return true;
}
void solve() {
	cin >> len >> m;
	for (int i = 1;i <= m;++i)
		cin >> p[i];
	p[m+1] = len+1;
	if (!valid()) 
		return cout << -1 << '\n', void();
}
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int T;
	cin >> T;
	while (T--)
		solve();
}

Compilation message

del13.cpp: In function 'bool valid()':
del13.cpp:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
del13.cpp:19:2: note: in expansion of macro 'DE'
   19 |  DE(len, m);
      |  ^~
del13.cpp:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
del13.cpp:26:2: note: in expansion of macro 'DE'
   26 |  DE(len, m);
      |  ^~
del13.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 0
      |                    ^
del13.cpp:27:2: note: in expansion of macro 'debug'
   27 |  debug(dis+1, dis+m+1);
      |  ^~~~~
del13.cpp:14:17: warning: statement has no effect [-Wunused-value]
   14 | #define DE(...) 0
      |                 ^
del13.cpp:51:3: note: in expansion of macro 'DE'
   51 |   DE(i, dp_min[i], dp_max[i]);
      |   ^~
del13.cpp:61:7: warning: unused variable 'u' [-Wunused-variable]
   61 |   int u = dp_max[i-1], d = dp_min[i-1], h = dis[i];
      |       ^
del13.cpp:61:24: warning: unused variable 'd' [-Wunused-variable]
   61 |   int u = dp_max[i-1], d = dp_min[i-1], h = dis[i];
      |                        ^
del13.cpp:61:41: warning: unused variable 'h' [-Wunused-variable]
   61 |   int u = dp_max[i-1], d = dp_min[i-1], h = dis[i];
      |                                         ^
del13.cpp:59:17: warning: unused variable 'nxt_h' [-Wunused-variable]
   59 |  int tar_h = 0, nxt_h, cur_h = dis[m] ;
      |                 ^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 9]
2 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 8]
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 9]
2 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 8]
3 Incorrect 6 ms 416 KB Integer 0 violates the range [1, 17]
4 Incorrect 5 ms 384 KB Integer 0 violates the range [1, 18]
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 512 KB Integer 0 violates the range [1, 28]
2 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 9]
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 9]
2 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 8]
3 Incorrect 6 ms 416 KB Integer 0 violates the range [1, 17]
4 Incorrect 5 ms 384 KB Integer 0 violates the range [1, 18]
5 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 100]
6 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 100]
7 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 53]
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 9]
2 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 8]
3 Incorrect 6 ms 416 KB Integer 0 violates the range [1, 17]
4 Incorrect 5 ms 384 KB Integer 0 violates the range [1, 18]
5 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 100]
6 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 100]
7 Incorrect 1 ms 384 KB Integer 0 violates the range [1, 53]
8 Incorrect 7 ms 640 KB Integer 0 violates the range [1, 87]
9 Incorrect 8 ms 876 KB Integer 0 violates the range [1, 94]
10 Incorrect 7 ms 1024 KB Integer 0 violates the range [1, 99]
11 Incorrect 13 ms 1984 KB Integer 0 violates the range [1, 81]