# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
720402 | yellowtoad | Automobil (COCI17_automobil) | C++17 | 19 ms | 15964 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 <iostream>
#include <vector>
using namespace std;
const long long mod = 1000000007;
long long int n, m, k, x, y, sum = 0, b[2][1000010];
char ch;
vector<pair<long long,long long>> a[2]; // R = 0; S = 1;
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= k; i++) {
cin >> ch >> x >> y;
for (int j = 0; j < a[ch%2].size(); j++) {
if (a[ch%2][j].first == x) {
a[ch%2][j].second *= y;
a[ch%2][j].second %= mod;
goto skip;
}
}
a[ch%2].push_back({x,y});
skip:;
}
for (int i = 1; i <= n; i++) b[0][i] = ((m*(i-1))+1+(m*(i-1))+m)*m/2;
for (int i = 1; i <= m; i++) b[1][i] = (i+((n-1)*m)+i)*n/2;
for (int i = 1; i <= n; i++) {
sum += b[0][i];
sum %= mod;
}
for (int i = 0; i < a[0].size(); i++) {
sum += ((b[0][a[0][i].first]%mod)*((a[0][i].second-1)%mod)+mod)%mod;
sum = (sum+mod)%mod;
}
for (int i = 0; i < a[1].size(); i++) {
sum += ((b[1][a[1][i].first]%mod)*((a[1][i].second-1)%mod)+mod)%mod;
sum = (sum+mod)%mod;
}
for (int i = 0; i < a[0].size(); i++) {
for (int j = 0; j < a[1].size(); j++) {
sum = (sum-((((a[0][i].first-1)*m+a[1][j].first)%mod)*(a[0][i].second%mod))%mod-((((a[0][i].first-1)*m+a[1][j].first)%mod)*(a[1][j].second%mod))%mod+((((a[0][i].first-1)*m+a[1][j].first)%mod)*((((a[1][j].second%mod)*(a[0][i].second%mod))+1)%mod))%mod)%mod;
sum = (sum+mod)%mod;
}
}
cout << (sum+mod)%mod << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |