답안 #236731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236731 2020-06-03T07:05:57 Z VEGAnn Automobil (COCI17_automobil) C++14
65 / 100
1000 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);
        }

    }

    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 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 6 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 6 ms 384 KB Output is correct
10 Correct 7 ms 384 KB Output is correct
11 Correct 276 ms 896 KB Output is correct
12 Execution timed out 1090 ms 1920 KB Time limit exceeded
13 Correct 103 ms 512 KB Output is correct
14 Correct 129 ms 1932 KB Output is correct
15 Execution timed out 1094 ms 2304 KB Time limit exceeded
16 Execution timed out 1090 ms 4352 KB Time limit exceeded
17 Execution timed out 1091 ms 4224 KB Time limit exceeded
18 Execution timed out 1092 ms 4224 KB Time limit exceeded
19 Execution timed out 1093 ms 4224 KB Time limit exceeded
20 Execution timed out 1095 ms 4224 KB Time limit exceeded