답안 #824538

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824538 2023-08-14T07:28:24 Z 이동현(#10361) 로봇 골프 (ROI19_golf) C++17
0 / 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;
	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] || (x[0] + x[1] == y[0] + y[1] && x[1] < y[1]);
	});

	int ans = 0;
	auto sol = [&](int bt){
		vector<int> dp(n + m - 1 + bt + 2);

		int ap = k - 1;
		for(int i = n + m - 2 + bt; i >= 0; i -= 2){
			auto pos = [&](int x, int y){
				assert((n + bt - x - 1 - (m - y - 1)) % 2 == 0);
				return m - 1 + (n + bt - x - 1 - (m - y - 1)) / 2 + 1;
			};
			while(ap >= 0 && a[ap][0] + a[ap][1] == i){
				dp[pos(a[ap][0], a[ap][1])] = a[ap][2];
				--ap;
			}

			// cout << i << endl;
			// for(auto&j:dp) cout << j << ' ';
			// cout << endl;

			for(int x = 0; x <= i; ++x){
				int y = i - x;
				if(x < n && y < m){
					(ans += dp[pos(x, y)] + mod * 2) %= mod;
					// cout << dp[pos(x, y)] << endl;
				}
			}
				// cout << endl;

			for(int i = 1; i + 1 < (int)dp.size(); ++i){
				if(dp[i] < dp[i - 1] && dp[i] < dp[i + 1]){
					dp[i] = min(dp[i - 1], dp[i + 1]);
				}
			}
			while(ap >= 0 && a[ap][0] + a[ap][1] == i - 1){
				int j = ap;
				while(j - 1 >= 0 && a[j - 1][0] + a[j - 1][1] == i - 1 && a[j][1] - 1 == a[j - 1][1]){
					--j;
				}

				int p = pos(a[j][0] + 1, a[j][1]);
				assert(p > 0);
				dp[p] = min(a[j][2], max(dp[p], dp[p - 1]));
				for(int k = j; k < ap; ++k){
					dp[p + k - j + 1] = min(a[k][2], a[k + 1][2]);
				}
				assert(p + ap - j + 1 + 1 < (int)dp.size());
				dp[p + ap - j + 1] = min(a[ap][2], max(dp[p + ap - j + 1], dp[p + ap - j + 2]));

				ap = j - 1;			
			}
		}
	};
	sol(0);
	sol(1);

	cout << ans << '\n';
	
	return 0;
}
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 8 ms 212 KB Output is correct
10 Incorrect 45 ms 3184 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5037 ms 3440 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 8 ms 212 KB Output is correct
10 Incorrect 45 ms 3184 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5063 ms 4208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5063 ms 4208 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 8 ms 212 KB Output is correct
10 Incorrect 45 ms 3184 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 188 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 8 ms 212 KB Output is correct
10 Incorrect 45 ms 3184 KB Output isn't correct
11 Halted 0 ms 0 KB -