Submission #308322

# Submission time Handle Problem Language Result Execution time Memory
308322 2020-09-30T22:57:09 Z Marlov Automobil (COCI17_automobil) C++14
20 / 100
27 ms 16128 KB
/*
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);
		}
	}

	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;
	}
	sum-=((N*M)*(1+N*M))%MOD/2;
	cout<<sum%MOD<<'\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
1 Incorrect 10 ms 16128 KB Output isn't correct
2 Incorrect 11 ms 16000 KB Output isn't correct
3 Correct 9 ms 15972 KB Output is correct
4 Incorrect 10 ms 16000 KB Output isn't correct
5 Correct 10 ms 16000 KB Output is correct
6 Correct 10 ms 16000 KB Output is correct
7 Incorrect 11 ms 16000 KB Output isn't correct
8 Correct 10 ms 16000 KB Output is correct
9 Incorrect 11 ms 16000 KB Output isn't correct
10 Incorrect 11 ms 16000 KB Output isn't correct
11 Incorrect 14 ms 16128 KB Output isn't correct
12 Incorrect 20 ms 16000 KB Output isn't correct
13 Incorrect 11 ms 16000 KB Output isn't correct
14 Incorrect 17 ms 16000 KB Output isn't correct
15 Incorrect 19 ms 16028 KB Output isn't correct
16 Incorrect 26 ms 16000 KB Output isn't correct
17 Incorrect 26 ms 16000 KB Output isn't correct
18 Incorrect 26 ms 16000 KB Output isn't correct
19 Incorrect 27 ms 16000 KB Output isn't correct
20 Incorrect 26 ms 16000 KB Output isn't correct