# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
308317 | Marlov | Automobil (COCI17_automobil) | C++14 | 26 ms | 16092 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.
/*
Code by @marlov
*/
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <iterator>
using namespace std;
typedef long long ll;
typedef pair<long long,long long> pi;
#define maxV 1000002
#define MOD 1000000007
struct mult{
char c;
long long x,m;
};
long long N,M,K;
long long sum=0;
long long row[maxV];
long long col[maxV];
mult arr[1000];
set<long long> rws;
set<long long> cls;
long long vRow(long long n){
long long val=(M*(((M*n)%MOD+1)+((M*n)%MOD+M))%MOD)/2;
val%=MOD;
// val+=M*n;
return val%MOD;
}
long long vCol(long long n){
long long val=(N*(n+1+n+1+(M*(N-1))%MOD)%MOD)/2;
return val%MOD;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>N>>M>>K;
fill(row,row+maxV,1);
fill(col,col+maxV,1);
for(long long i=0;i<K;i++){
cin>>arr[i].c>>arr[i].x>>arr[i].m;
arr[i].x--;
if(arr[i].c=='R'){
row[arr[i].x]*=arr[i].m;
row[arr[i].x]%=MOD;
rws.insert(arr[i].x);
}else if(arr[i].c=='S'){
col[arr[i].x]*=arr[i].m;
col[arr[i].x]%=MOD;
cls.insert(arr[i].x);
}
}
sum-=((N*M)%MOD*(1+N*M)%MOD)/2;
sum%=MOD;
for(long long cr:rws){
for(long long cc:cls){
long long cv=cr*M+cc+1;
sum+=cv;
sum-=row[cr]*cv;
sum-=col[cc]*cv;
sum%=MOD;
//cout<<sum<<"\n";
sum+=((row[cr]*col[cc])%MOD)*cv;
sum%=MOD;
//cout<<cv<<" creates "<<sum<<'\n';
}
}
//for rows
//cout<<sum<<'\n';
for(long long i=0;i<N;i++){
//cout<<vRow(i)<<'\n';
sum+=(row[i])*vRow(i);
//cout<<"row "<<i<<": "<<sum<<'\n';
sum%=MOD;
}
//for col
for(long long i=0;i<M;i++){
//cout<<vCol(i)<<'\n';
sum+=(col[i])*vCol(i);
//cout<<"col "<<i<<": "<<sum<<'\n';
sum%=MOD;
}
cout<<sum<<'\n';
return 0;
}
/* stuff you should look for
* long long overflow, array bounds
* special cases (n=1,n=0?)
* do smth instead of nothing and stay organized
*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |