QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644666#9221. Missing Boundariesucup-team2432#WA 36ms11180kbC++202.2kb2024-10-16 15:00:492024-10-16 15:00:50

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 15:00:50]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:11180kb
  • [2024-10-16 15:00:49]
  • 提交

answer

#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(),vec.end()
#define umap __gnu_pbds::gp_hash_table
using ll = long long;
using i128 = __int128;
using db = double;
#define Emu Smile
using namespace std;

void chmax(auto &a, auto b) { if (a < b) a = b; }
void chmin(auto &a, auto b) { if (a > b) a = b; }
inline int lbt(int x) { return x & (-x); }

const int P = 1e9+7, B = 1000;
const ll inf = 1e4;

void yes() {
	cout << "TAK\n";
}

void no() {
	cout << "NIE\n";
}

void solve() {
	int n; ll L; cin >> n >> L;
	ll ff = 0;
	vector<array<ll,3>> edge;
	for (int i = 0, x, y; i < n; ++i) {
		cin >> x >> y;
		if (x == -1 && y == -1) {
			ff ++;
		} else if (x == -1) {
			edge.push_back({y-1, y, 1});		// <-
		} else if (y == -1) {
			x --;
			edge.push_back({x, x+1, 2});	// ->
		} else {
			x --;
			edge.push_back({x, y, 0});
		}
	}
	n = sz(edge);
	if (n == 0) {
		if (ff <= L) return yes();
		else return no();
	}
	sort(all(edge), [&](array<ll,3> x, array<ll,3> y) {
		return x[0] < y[0];
	});
	int maxr = 0;
	for (int i = 0; i < n; ++i) {
		if (maxr > edge[i][0]) return no();
		chmax(maxr, edge[i][1]);
	}
	ll ffL = 0, ffR = 0;
	for (int i = 0; i < n; ++i) {
		if (edge[i][2] == 1) {
			int newl = 0;
			if (i > 0) newl = edge[i-1][1];
			ffR += edge[i][0] - newl;
			edge[i][0] = newl;
		} else if (edge[i][2] == 2) {
			int newr = L;
			if (i + 1 < n) newr = edge[i+1][0];
			ffR += newr - edge[i][1];
			edge[i][1] = newr;
		}
	}
	for (int i = 0; i < n; ++i) {
		int preR = 0;
		if (i > 0) preR = edge[i-1][1];
		if (preR != edge[i][0]) {
			ffL ++; ffR += edge[i][0] - preR;
		}
		int nxtL = L;
		if (i + 1 < n) nxtL = edge[i+1][0];
		if (nxtL != edge[i][1]) {
			ffL ++; ffR += nxtL - edge[i][1];
		}
	}
	if (ffL <= ff && ff <= ffR) {
		return yes();
	} else {
		return no();
	}
}

int main() {

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);

//	init();

	cout << fixed << setprecision(10);

	int OuO = 1;
	cin >> OuO;
	for (int piastic = 0; piastic < OuO; ++piastic) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3552kb

input:

3
4 51
1 -1
11 50
-1 -1
-1 10
3 2
-1 -1
-1 -1
-1 -1
2 3
1 2
2 3

output:

TAK
NIE
NIE

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 36ms
memory: 11060kb

input:

1
200000 1000000000
490669427 -1
224278942 224287156
821104480 -1
861696576 861702036
807438935 807440055
574078002 574083717
465630141 -1
195378188 -1
-1 13500961
-1 977536179
92893115 -1
-1 661145418
-1 215804863
-1 685338515
544348999 -1
465532902 -1
130346949 -1
-1 526666304
635604584 635605404
...

output:

TAK

result:

ok single line: 'TAK'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

3
4 51
1 -1
11 50
-1 -1
-1 10
3 2
-1 -1
-1 -1
-1 -1
2 3
1 2
2 3

output:

TAK
NIE
NIE

result:

ok 3 lines

Test #4:

score: -100
Wrong Answer
time: 27ms
memory: 11180kb

input:

1
197838 400000
34167 34169
352180 -1
235963 -1
-1 -1
160401 160405
347288 -1
270353 270354
214502 214504
183243 183245
-1 -1
-1 36193
-1 -1
-1 17557
273498 273500
269137 -1
395099 395100
285515 285518
-1 -1
71041 71042
324060 -1
-1 385151
-1 379645
-1 -1
-1 185142
-1 191584
89259 89261
328347 32834...

output:

NIE

result:

wrong answer 1st lines differ - expected: 'TAK', found: 'NIE'