Submission #49271009


Source Code Expand

// LUOGU_RID: 142826467
#include <bits/stdc++.h>//°ÑDAGÍË»¯ÎªÊ÷£¬È»ºó×öÊ÷ÐÎdp
using namespace std;

const int maxn = 2e5 + 10, mod = 998244353;
int n;
struct node {
	int x_i, d_i;
}a[maxn];
stack < int > s;
int dp[maxn];
vector < int > to[maxn];
int fat[maxn];

bool cmp(node a, node b) {
	return a.x_i < b.x_i;
}

void dfs(int x) {
	dp[x] = 1;
	int res = 1;
	for(auto v : to[x]) dfs(v), res = (1LL * res * dp[v]) % mod;
	dp[x] = (dp[x] + res) % mod;
}

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) scanf("%d%d", &a[i].x_i, &a[i].d_i);
	sort(a + 1, a + n + 1, cmp);
	for(int i = n; i >= 1; i --) {
		while(!s.empty() && a[i].x_i + a[i].d_i > a[s.top()].x_i) fat[s.top()] = i, to[i].push_back(s.top()), s.pop();
		s.push(i);
	}
	int ans = 1;
	for(int i = 1; i <= n; i ++) {
		if(!fat[i]) dfs(i), ans = (1LL * ans * dp[i]) % mod;
	}
	printf("%d\n", ans);
	return 0;
}

Submission Info

Submission Time
Task F - Removing Robots
User brain
Language C++ 17 (gcc 12.2)
Score 600
Code Size 941 Byte
Status AC
Exec Time 76 ms
Memory 30424 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:27:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
Main.cpp:28:43: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   28 |         for(int i = 1; i <= n; i ++) scanf("%d%d", &a[i].x_i, &a[i].d_i);
      |                                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 4
AC × 26
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt, s4.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, s1.txt, s2.txt, s3.txt, s4.txt
Case Name Status Exec Time Memory
01.txt AC 3 ms 8516 KiB
02.txt AC 3 ms 8628 KiB
03.txt AC 3 ms 8496 KiB
04.txt AC 3 ms 8568 KiB
05.txt AC 3 ms 8384 KiB
06.txt AC 3 ms 8380 KiB
07.txt AC 3 ms 8492 KiB
08.txt AC 3 ms 8420 KiB
09.txt AC 3 ms 8492 KiB
10.txt AC 3 ms 8496 KiB
11.txt AC 67 ms 18696 KiB
12.txt AC 67 ms 19600 KiB
13.txt AC 66 ms 18420 KiB
14.txt AC 52 ms 18504 KiB
15.txt AC 75 ms 30424 KiB
16.txt AC 76 ms 30252 KiB
17.txt AC 62 ms 30388 KiB
18.txt AC 62 ms 14944 KiB
19.txt AC 3 ms 8508 KiB
20.txt AC 70 ms 28468 KiB
21.txt AC 71 ms 28776 KiB
22.txt AC 70 ms 28616 KiB
s1.txt AC 3 ms 8496 KiB
s2.txt AC 3 ms 8416 KiB
s3.txt AC 3 ms 8448 KiB
s4.txt AC 3 ms 8388 KiB