답안 #824661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824661 2023-08-14T08:38:37 Z 이동현(#10361) 로봇 골프 (ROI19_golf) C++17
20 / 100
5000 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;
	cin >> n >> m >> k;
    swap(n, m);
	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];
        swap(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(m + 4), ndp(m + 4);

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

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

            if(cnt > 5 && i < n && n > 1000 && m <= 5){
                int nxt = i % 2;
                if(ap >= 0) nxt = a[ap][0] + a[ap][1] + (a[ap][0] + a[ap][1] + i) % 2;
                nxt = max(nxt, 10 + i % 2);

                if(nxt < i){
                    int add = 0;
                    for(int x = 0; x <= i; ++x){
                        int y = i - x;
                        if(x < n && y < m){
                            (add += dp[y] + mod * 2) %= mod;
                        }
                    }

                    ans += add * (i - nxt) / 2;
                    i = nxt;
                    cnt = 0;
                }
            }

			if(!bt){
				for(int x = 0; x <= i; ++x){
					int y = i - x;
					if(x < n && y < m){
						(ans += dp[y] + mod * 2) %= mod;
					}
				}
			}

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

	cout << ans << '\n';
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 9 ms 332 KB Output is correct
10 Correct 50 ms 2672 KB Output is correct
11 Correct 40 ms 2676 KB Output is correct
12 Correct 40 ms 2672 KB Output is correct
13 Correct 40 ms 2672 KB Output is correct
14 Correct 33 ms 2672 KB Output is correct
15 Correct 39 ms 2664 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 41 ms 2684 KB Output is correct
23 Correct 38 ms 2680 KB Output is correct
24 Correct 38 ms 2660 KB Output is correct
25 Correct 37 ms 2644 KB Output is correct
26 Correct 37 ms 2684 KB Output is correct
27 Correct 39 ms 2672 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 30 ms 2672 KB Output is correct
33 Correct 36 ms 2644 KB Output is correct
34 Correct 22 ms 2644 KB Output is correct
35 Correct 23 ms 2680 KB Output is correct
36 Correct 22 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 24 ms 724 KB Output is correct
4 Incorrect 1769 ms 2644 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1774 ms 2644 KB Output is correct
2 Execution timed out 5101 ms 4172 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 9 ms 332 KB Output is correct
10 Correct 50 ms 2672 KB Output is correct
11 Correct 40 ms 2676 KB Output is correct
12 Correct 40 ms 2672 KB Output is correct
13 Correct 40 ms 2672 KB Output is correct
14 Correct 33 ms 2672 KB Output is correct
15 Correct 39 ms 2664 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 41 ms 2684 KB Output is correct
23 Correct 38 ms 2680 KB Output is correct
24 Correct 38 ms 2660 KB Output is correct
25 Correct 37 ms 2644 KB Output is correct
26 Correct 37 ms 2684 KB Output is correct
27 Correct 39 ms 2672 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 30 ms 2672 KB Output is correct
33 Correct 36 ms 2644 KB Output is correct
34 Correct 22 ms 2644 KB Output is correct
35 Correct 23 ms 2680 KB Output is correct
36 Correct 22 ms 2640 KB Output is correct
37 Runtime error 202 ms 524288 KB Execution killed with signal 9
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5083 ms 4208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5083 ms 4208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 9 ms 332 KB Output is correct
10 Correct 50 ms 2672 KB Output is correct
11 Correct 40 ms 2676 KB Output is correct
12 Correct 40 ms 2672 KB Output is correct
13 Correct 40 ms 2672 KB Output is correct
14 Correct 33 ms 2672 KB Output is correct
15 Correct 39 ms 2664 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 41 ms 2684 KB Output is correct
23 Correct 38 ms 2680 KB Output is correct
24 Correct 38 ms 2660 KB Output is correct
25 Correct 37 ms 2644 KB Output is correct
26 Correct 37 ms 2684 KB Output is correct
27 Correct 39 ms 2672 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 30 ms 2672 KB Output is correct
33 Correct 36 ms 2644 KB Output is correct
34 Correct 22 ms 2644 KB Output is correct
35 Correct 23 ms 2680 KB Output is correct
36 Correct 22 ms 2640 KB Output is correct
37 Correct 1774 ms 2644 KB Output is correct
38 Execution timed out 5101 ms 4172 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 162 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 9 ms 332 KB Output is correct
10 Correct 50 ms 2672 KB Output is correct
11 Correct 40 ms 2676 KB Output is correct
12 Correct 40 ms 2672 KB Output is correct
13 Correct 40 ms 2672 KB Output is correct
14 Correct 33 ms 2672 KB Output is correct
15 Correct 39 ms 2664 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 3 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 41 ms 2684 KB Output is correct
23 Correct 38 ms 2680 KB Output is correct
24 Correct 38 ms 2660 KB Output is correct
25 Correct 37 ms 2644 KB Output is correct
26 Correct 37 ms 2684 KB Output is correct
27 Correct 39 ms 2672 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 30 ms 2672 KB Output is correct
33 Correct 36 ms 2644 KB Output is correct
34 Correct 22 ms 2644 KB Output is correct
35 Correct 23 ms 2680 KB Output is correct
36 Correct 22 ms 2640 KB Output is correct
37 Correct 1774 ms 2644 KB Output is correct
38 Execution timed out 5101 ms 4172 KB Time limit exceeded
39 Halted 0 ms 0 KB -