답안 #236732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236732 2020-06-03T07:12:06 Z VEGAnn Automobil (COCI17_automobil) C++14
100 / 100
11 ms 4352 KB
#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define ft first
#define sd second
using namespace std;
const int N = 1000100;
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;}
void 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);
        }

    }

    int sm = mult(mult(sum(2, mult(n - 1, m)), n), inv2), ad = n;

    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, 1);

            ad = sub(ad, 1);

            int real_val = sum(mult(x - 1, m), 1);
            MULT(real_val, cf);

            ad = sum(ad, cf);

            sm = sum(sm, real_val);
        }
    }

    ans = sum(ans, mult(sm, col[1]));

    for (int j = 2; j <= m; j++){
        sm = sum(sm, ad);

        if (col[j] == 0) continue;

        ans = sum(ans, mult(sm, col[j]));
    }

    cout << ans << '\n';

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 6 ms 896 KB Output is correct
12 Correct 7 ms 1920 KB Output is correct
13 Correct 5 ms 512 KB Output is correct
14 Correct 7 ms 1920 KB Output is correct
15 Correct 8 ms 2304 KB Output is correct
16 Correct 11 ms 4224 KB Output is correct
17 Correct 11 ms 4224 KB Output is correct
18 Correct 11 ms 4352 KB Output is correct
19 Correct 11 ms 4352 KB Output is correct
20 Correct 11 ms 4224 KB Output is correct