QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#583895#9221. Missing BoundariesChief_NingWA 38ms7024kbC++202.3kb2024-09-22 23:42:092024-09-22 23:42:10

Judging History

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

  • [2024-09-22 23:42:10]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:7024kb
  • [2024-09-22 23:42:09]
  • 提交

answer

//https://contest.ucup.ac/contest/1774/problem/9221
#include<bits/stdc++.h>
using namespace std;

using u64 = unsigned long long;
using u32 = unsigned int;
using i64 = long long;

mt19937_64 rnd(random_device{}());

const int mod = 998244353;
const int N = 3e5 + 5;
const int M = 2e5 + 5;

int n, m, s, t;

struct segment {
	int l, r, min;
};

int L;

void RuinGuard(int tc)
{
	cin >> n >> L;
	
	int cnt = 0;
	
	vector<segment> seg(1, {0, 0, 0});
	for(int i = 1; i <= n; i++) {
		int ll, rr;
		cin >> ll >> rr;
		if(ll == -1 && rr == -1) {
			cnt += 1;
		} else if(ll == -1) {
			seg.push_back({ll, rr, rr});
		} else if(rr == -1) {
			seg.push_back({ll, rr, ll});
		} else {
			seg.push_back({ll, rr, min(ll, rr)});
		}
	}
	
	int siz = seg.size() - 1;
	
	if(!siz) {
		if(n <= L) {
			return cout << "TAK\n", void();
		} else {
			return cout << "NIE\n", void();
		}
	}
	
	sort(seg.begin() + 1, seg.end(), [&](segment& a, segment& b) -> bool {
		return a.min < b.min;
	});
	
	for(int i = 1; i <= siz; i++) {
		if(seg[i].l == -1 || seg[i].r == -1) continue;
		if(seg[i].l > seg[i].r) {
			return cout << "NIE\n", void();
		}
	}
	
	int needNum = 0, canNum = 0;
	
	if(seg[1].l != 1) {
		if(seg[1].l == -1) {
			canNum += seg[1].r - 1;
		} else {
			needNum += 1;
			canNum += seg[1].l - 1;
		}
	}
	
	for(int i = 1; i < siz; i++) {
		if(seg[i].min == seg[i + 1].min) {
			return cout << "NIE\n", void();
		}
		int lft = seg[i].r, rgt = seg[i + 1].l;
		if(lft != -1 && rgt != -1) {
			if(lft >= rgt) {
				return cout << "NIE\n", void();
			}
			int dis = rgt - lft - 1;
			if(dis) {
				needNum += 1;
				canNum += dis;
			}
		} else if(lft == -1) {
			needNum += rgt - seg[i].l - 1;
		} else {
			needNum += seg[i + 1].r - lft - 1;
		} 
	}
	
	if(seg[siz].r != L) {
		if(seg[siz].r == -1) {
			canNum += L - seg[siz].l;
		} else {
			needNum += 1;
			canNum += L - seg[siz].r;
		}
	}
	
	if(cnt >= needNum && cnt <= canNum) {
		return cout << "TAK\n", void();
	} else {
		return cout << "NIE\n", void();
	}
}

signed main()
{ 
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int testcase = 1;
	cin >> testcase;
	
    for(int tc = 1; tc <= testcase; tc++) {
    	RuinGuard(tc);
	}

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3604kb

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: 38ms
memory: 7024kb

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: 3628kb

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: 33ms
memory: 6296kb

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'