Submission #824625

# Submission time Handle Problem Language Result Execution time Memory
824625 2023-08-14T08:21:56 Z 이동현(#10361) Robogolf (ROI19_golf) C++17
20 / 100
1746 ms 524288 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

const int mod = 998244353;

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, m, k;

	// n = 1000, m = 1000, k = 300000;
	// mt19937 gen(2353);
	// uniform_int_distribution<int> uid(-100, 100);
	// vector<array<int, 3>> a(k);
	// for(int i = 0; i < k; ++i){
	// 	a[i] = {i * (n * m / k) / m, i * (n * m / k) % m, uid(gen)};
	// }

	cin >> n >> m >> k;
	vector<array<int, 3>> a(k);
	for(int i = 0; i < k; ++i){
		cin >> a[i][0] >> a[i][1] >> a[i][2];
		--a[i][0], --a[i][1];
	}

	sort(a.begin(), a.end(), [&](array<int, 3>&x, array<int, 3>&y){return x[0] + x[1] < y[0] + y[1];});

	int ans = 0;
	auto sol = [&](int bt){
		vector<int> dp(n + m), ndp(n + m), pre(n + m);

		int ap = k - 1;
		for(int i = n + m - 2; i >= 0; --i){
            if(i + 2010 >= n + m - 2){
                for(int j = 0; j < n + m - 1; ++j){
                    if(!bt) ndp[j] = min(dp[j], dp[j + 1]);
                    else ndp[j] = max(dp[j], dp[j + 1]);
                }
                swap(dp, ndp);
                for(int j = 0; j < n + m; ++j){
                    pre[j] = dp[j];
                    if(j) pre[j] += pre[j - 1];
                }
            }

			while(ap >= 0 && a[ap][0] + a[ap][1] == i){
				dp[a[ap][1]] = a[ap][2];
				--ap;
			}

            if(i + 2010 >= n + m - 2){
                for(int j = 0; j < n + m; ++j){
                    pre[j] = dp[j];
                    if(j) pre[j] += pre[j - 1];
                }
            }

			if(!bt){
                int l = 0, r = 0;
                if(n <= m){
                    if(i <= n - 1) l = 0, r = i;
                    else if(i <= m - 1) l = i - n + 1, r = i;
                    else l = i - n + 1, r = m - 1;
                }
                else{
                    if(i <= m - 1) l = 0, r = i;
                    else if(i <= n - 1) l = 0, r = m - 1;
                    else l = i - n + 1, r = m - 1;
                }
                // cout << i << ' ' << l << ' ' << r << endl;
                // cout << pre[r] << endl;
				(ans += pre[r] % mod + mod) %= mod;
                if(l) (ans += -pre[l - 1] % mod + mod) % mod;
			}

			bt ^= 1;
		}
	};
	sol(0);
	sol(1);

	cout << ans << '\n';
	
	return 0;
}

Compilation message

golf.cpp: In lambda function:
golf.cpp:78:56: warning: value computed is not used [-Wunused-value]
   78 |                 if(l) (ans += -pre[l - 1] % mod + mod) % mod;
      |                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 17 ms 340 KB Output is correct
10 Correct 49 ms 2784 KB Output is correct
11 Correct 51 ms 2780 KB Output is correct
12 Correct 48 ms 2800 KB Output is correct
13 Correct 50 ms 2808 KB Output is correct
14 Correct 38 ms 2804 KB Output is correct
15 Correct 38 ms 2792 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 8 ms 584 KB Output is correct
19 Correct 6 ms 460 KB Output is correct
20 Correct 5 ms 340 KB Output is correct
21 Correct 4 ms 340 KB Output is correct
22 Correct 48 ms 2800 KB Output is correct
23 Correct 53 ms 2800 KB Output is correct
24 Correct 45 ms 2752 KB Output is correct
25 Correct 46 ms 2792 KB Output is correct
26 Correct 47 ms 2796 KB Output is correct
27 Correct 47 ms 2788 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 5 ms 340 KB Output is correct
30 Correct 5 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 35 ms 2752 KB Output is correct
33 Correct 42 ms 2776 KB Output is correct
34 Correct 24 ms 2776 KB Output is correct
35 Correct 25 ms 2720 KB Output is correct
36 Correct 25 ms 2752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 85 ms 1088 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 898 ms 5020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 17 ms 340 KB Output is correct
10 Correct 49 ms 2784 KB Output is correct
11 Correct 51 ms 2780 KB Output is correct
12 Correct 48 ms 2800 KB Output is correct
13 Correct 50 ms 2808 KB Output is correct
14 Correct 38 ms 2804 KB Output is correct
15 Correct 38 ms 2792 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 8 ms 584 KB Output is correct
19 Correct 6 ms 460 KB Output is correct
20 Correct 5 ms 340 KB Output is correct
21 Correct 4 ms 340 KB Output is correct
22 Correct 48 ms 2800 KB Output is correct
23 Correct 53 ms 2800 KB Output is correct
24 Correct 45 ms 2752 KB Output is correct
25 Correct 46 ms 2792 KB Output is correct
26 Correct 47 ms 2796 KB Output is correct
27 Correct 47 ms 2788 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 5 ms 340 KB Output is correct
30 Correct 5 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 35 ms 2752 KB Output is correct
33 Correct 42 ms 2776 KB Output is correct
34 Correct 24 ms 2776 KB Output is correct
35 Correct 25 ms 2720 KB Output is correct
36 Correct 25 ms 2752 KB Output is correct
37 Runtime error 225 ms 524288 KB Execution killed with signal 9
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1746 ms 7356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1746 ms 7356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 17 ms 340 KB Output is correct
10 Correct 49 ms 2784 KB Output is correct
11 Correct 51 ms 2780 KB Output is correct
12 Correct 48 ms 2800 KB Output is correct
13 Correct 50 ms 2808 KB Output is correct
14 Correct 38 ms 2804 KB Output is correct
15 Correct 38 ms 2792 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 8 ms 584 KB Output is correct
19 Correct 6 ms 460 KB Output is correct
20 Correct 5 ms 340 KB Output is correct
21 Correct 4 ms 340 KB Output is correct
22 Correct 48 ms 2800 KB Output is correct
23 Correct 53 ms 2800 KB Output is correct
24 Correct 45 ms 2752 KB Output is correct
25 Correct 46 ms 2792 KB Output is correct
26 Correct 47 ms 2796 KB Output is correct
27 Correct 47 ms 2788 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 5 ms 340 KB Output is correct
30 Correct 5 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 35 ms 2752 KB Output is correct
33 Correct 42 ms 2776 KB Output is correct
34 Correct 24 ms 2776 KB Output is correct
35 Correct 25 ms 2720 KB Output is correct
36 Correct 25 ms 2752 KB Output is correct
37 Incorrect 898 ms 5020 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 165 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 17 ms 340 KB Output is correct
10 Correct 49 ms 2784 KB Output is correct
11 Correct 51 ms 2780 KB Output is correct
12 Correct 48 ms 2800 KB Output is correct
13 Correct 50 ms 2808 KB Output is correct
14 Correct 38 ms 2804 KB Output is correct
15 Correct 38 ms 2792 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 8 ms 584 KB Output is correct
19 Correct 6 ms 460 KB Output is correct
20 Correct 5 ms 340 KB Output is correct
21 Correct 4 ms 340 KB Output is correct
22 Correct 48 ms 2800 KB Output is correct
23 Correct 53 ms 2800 KB Output is correct
24 Correct 45 ms 2752 KB Output is correct
25 Correct 46 ms 2792 KB Output is correct
26 Correct 47 ms 2796 KB Output is correct
27 Correct 47 ms 2788 KB Output is correct
28 Correct 4 ms 340 KB Output is correct
29 Correct 5 ms 340 KB Output is correct
30 Correct 5 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 35 ms 2752 KB Output is correct
33 Correct 42 ms 2776 KB Output is correct
34 Correct 24 ms 2776 KB Output is correct
35 Correct 25 ms 2720 KB Output is correct
36 Correct 25 ms 2752 KB Output is correct
37 Incorrect 898 ms 5020 KB Output isn't correct
38 Halted 0 ms 0 KB -