답안 #631620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631620 2022-08-18T10:16:11 Z Justin1 Automobil (COCI17_automobil) C++14
100 / 100
123 ms 31644 KB
#include <bits/stdc++.h>
#define int __int128
using namespace std;
 
long long n,m,k,x,y,z;
int c[1000005], r[1000005];
char ch;
vector<int> colupd;
 
int mod(int x) {
	const int modval = 1e9+7;
	return ((x % modval) + modval) % modval;
}
 
signed main() {
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) r[i] = 1;
	for (int i = 1; i <= m; i++) c[i] = 1;
	for (int i = 1; i <= k; i++) {
		cin >> ch >> x >> y;
		if (ch == 'R') r[x] = mod(r[x] * y);
		else c[x] = mod(c[x] * y);
	}
	int ans;
	if (n*m & 1) ans = mod(mod((1 + n*m)/2) * mod(n*m));
	else ans = mod(mod(1 + n*m) * mod((n*m)/2));
	for (int i = 1; i <= m; i++) {
		if (c[i] != 1) colupd.push_back(i);
		ans += mod(mod(n*(2*i+(n-1)*m)/2) * mod(c[i]-1));
		ans = mod(ans);
	}
	for (int i = 1; i <= n; i++) {
		int st = m*(i-1)+1;
		ans += mod(mod(m*(2*st+m-1)/2) * mod(r[i]-1));
		if (r[i] != 1) {
			for (auto j : colupd) {
				int val = mod(m*(i-1) + j);
				ans -= mod(val * mod(r[i] + c[j] - 2));
				ans += mod(val * mod(r[i] * c[j] - 1));
			}
		}
		ans = mod(ans);
	}
	cout << (long long) ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 4 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 5 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 6 ms 380 KB Output is correct
11 Correct 20 ms 5204 KB Output is correct
12 Correct 67 ms 16980 KB Output is correct
13 Correct 7 ms 1492 KB Output is correct
14 Correct 66 ms 19876 KB Output is correct
15 Correct 66 ms 17768 KB Output is correct
16 Correct 113 ms 31644 KB Output is correct
17 Correct 113 ms 31636 KB Output is correct
18 Correct 121 ms 31628 KB Output is correct
19 Correct 116 ms 31632 KB Output is correct
20 Correct 123 ms 31636 KB Output is correct