# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
236729 | VEGAnn | Automobil (COCI17_automobil) | C++14 | 6 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define ft first
#define sd second
using namespace std;
const int N = 1010;
const int oo = int(2e9);
const int md = int(1e9) + 7;
unordered_map<int, int> row;
int n, m, k, col[N], inv2 = 500000004, ans = 0;
int mult(int x, int y) { return (1ll * x * y) % md;}
int MULT(int &x, int y) { x = mult(x, y); }
int sum(int x, int y){
x += y;
if (x >= md)
x -= md;
return x;
}
int sub(int x, int y){
x -= y;
if (x < 0)
x += md;
return x;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> m >> k;
fill(col + 1, col + m + 1, 1);
for (; k; k--){
char c; int x, y;
cin >> c >> x >> y;
if (c == 'R'){
if (row.find(x) == row.end())
row[x] = 1;
MULT(row[x], y);
} else {
MULT(col[x], y);
}
}
for (int j = 1; j <= m; j++){
if (col[j] == 0) continue;
int sm = mult(mult(sum(j + j, mult(n - 1, m)), n), inv2);
if (sz(row) > 0) {
for (auto cr : row){
int x = cr.ft, cf = cr.sd;
sm = sub(sm, mult(x - 1, m));
sm = sub(sm, j);
int real_val = sum(mult(x - 1, m), j);
MULT(real_val, cf);
sm = sum(sm, real_val);
}
}
ans = sum(ans, mult(sm, col[j]));
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |