QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#584251#9221. Missing BoundariesChief_NingWA 28ms7208kbC++202.5kb2024-09-23 10:55:452024-09-23 10:55:45

Judging History

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

  • [2024-09-23 10:55:45]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:7208kb
  • [2024-09-23 10:55:45]
  • 提交

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;
	});
	
	int needNum = 0, canNum = 0;
	
	for(int i = 1; i < siz; i++) {
		if(seg[i].min == seg[i + 1].min) {
			return cout << "NIE\n", void();
		}
		if(seg[i].r != -1 && seg[i + 1].l != -1) {
			if(seg[i].r >= seg[i + 1].l) {
				return cout << "NIE\n", void();
			}
			int dis = seg[i + 1].l - seg[i].r - 1;
			if(dis) {
				needNum += 1;
				canNum += dis;
			}
		} else if(seg[i].r == -1 && seg[i + 1].l == -1) {
			if(seg[i + 1].r - seg[i].l == 1) {
				return cout << "NIE\n", void();
			}
			canNum += seg[i + 1].r - seg[i].l - 1;
		} else if(seg[i].r == -1) {
			if(seg[i + 1].l - seg[i].l == 1) {
				return cout << "NIE\n", void();
			}
			canNum += seg[i + 1].l - seg[i].l - 1;
		} else {
			if(seg[i + 1].r - seg[i].r == 1) {
				return cout << "NIE\n", void();
			}
			canNum += seg[i + 1].r - seg[i].r - 1;
		} 
	}
	
	if(seg[1].l != 1) {
		if(seg[1].l == -1) {
			canNum += seg[1].r - 1;
		} else {
			needNum += 1;
			canNum += seg[1].l - 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;
}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 28ms
memory: 7208kb

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:

NIE

result:

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