Submission #317162

# Submission time Handle Problem Language Result Execution time Memory
317162 2020-10-29T04:28:35 Z Kevin_Zhang_TW DEL13 (info1cup18_del13) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#undef KEV
#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_rm = dis[m];
	//cerr << "height\n";
	debug(dis+1, dis+1+m);

	int old_cut = 0, tar_h = 0;
	
	for (int i = m;i >= 1;--i) {

		// must cut it for the previous one
		assert(cur_h >= dp_min[i] && cur_h <= dp_max[i]);

		int cut_back = dp_min[i-1];

		int cur_h = dis[i] - old_cut;

		int need_cut = cur_h - tar_h;

		DE(i, dis[i], cut_back, cur_h, need_cut);

		assert( need_cut >= cut_back );

		while (need_cut >= cut_back + 2 && cut_back + 2 <= dp_max[i-1])
			cut_back += 2;

		assert( need_cut >= cut_back );

		self[i] = (need_cut - cut_back) / 2;
	
		assert(need_cut % 2 == cut_back % 2);

		cnt[i] = cut_back;

		tar_h = 0;

		old_cut = cut_back;


	}
	//cerr << "self\n";
	debug(self.begin()+1, self.begin()+m+1);
	//cerr << "cnt\n";
	debug(cnt.begin()+1, cnt.begin()+m+1);

	//return true;
	vector<int> op;

	for (int i = 1;i <= m;++i) 
		while (self[i]--) {
			assert(dis[i] > 2);
			dis[i] -= 2;
			op.pb(p[i]-2);
		}

	for (int i = 1;i <= m;++i) {
		while (cnt[i]--)
			op.pb(p[i-1]), --dis[i], --dis[i-1];
	}
	for (int i = 1;i <= m;++i)
		assert(dis[i] == 0);

	//op.resize(need, 1);
	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:15:17: warning: statement has no effect [-Wunused-value]
   15 | #define DE(...) 0
      |                 ^
del13.cpp:20:2: note: in expansion of macro 'DE'
   20 |  DE(len, m);
      |  ^~
del13.cpp:15:17: warning: statement has no effect [-Wunused-value]
   15 | #define DE(...) 0
      |                 ^
del13.cpp:27:2: note: in expansion of macro 'DE'
   27 |  DE(len, m);
      |  ^~
del13.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
del13.cpp:28:2: note: in expansion of macro 'debug'
   28 |  debug(dis+1, dis+m+1);
      |  ^~~~~
del13.cpp:15:17: warning: statement has no effect [-Wunused-value]
   15 | #define DE(...) 0
      |                 ^
del13.cpp:52:3: note: in expansion of macro 'DE'
   52 |   DE(i, dp_min[i], dp_max[i]);
      |   ^~
del13.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
del13.cpp:63:2: note: in expansion of macro 'debug'
   63 |  debug(dis+1, dis+1+m);
      |  ^~~~~
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from del13.cpp:1:
del13.cpp:70:10: error: 'cur_h' was not declared in this scope
   70 |   assert(cur_h >= dp_min[i] && cur_h <= dp_max[i]);
      |          ^~~~~
del13.cpp:15:17: warning: statement has no effect [-Wunused-value]
   15 | #define DE(...) 0
      |                 ^
del13.cpp:78:3: note: in expansion of macro 'DE'
   78 |   DE(i, dis[i], cut_back, cur_h, need_cut);
      |   ^~
del13.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
del13.cpp:100:2: note: in expansion of macro 'debug'
  100 |  debug(self.begin()+1, self.begin()+m+1);
      |  ^~~~~
del13.cpp:14:20: warning: statement has no effect [-Wunused-value]
   14 | #define debug(...) 0
      |                    ^
del13.cpp:102:2: note: in expansion of macro 'debug'
  102 |  debug(cnt.begin()+1, cnt.begin()+m+1);
      |  ^~~~~
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from del13.cpp:1:
del13.cpp:122:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |  assert(need == op.size());
      |         ~~~~~^~~~~~~~~~~~
del13.cpp:61:6: warning: unused variable 'tar_rm' [-Wunused-variable]
   61 |  int tar_rm = dis[m];
      |      ^~~~~~