답안 #308311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308311 2020-09-30T22:47:38 Z Marlov Automobil (COCI17_automobil) C++14
55 / 100
23 ms 16000 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+1)+(M*n+M)))/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)))/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)*(1+N*M))/2;
	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
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16000 KB Output is correct
2 Correct 10 ms 16000 KB Output is correct
3 Correct 10 ms 16000 KB Output is correct
4 Correct 10 ms 16000 KB Output is correct
5 Correct 10 ms 16000 KB Output is correct
6 Correct 10 ms 16000 KB Output is correct
7 Correct 11 ms 16000 KB Output is correct
8 Correct 10 ms 16000 KB Output is correct
9 Correct 10 ms 16000 KB Output is correct
10 Correct 11 ms 16000 KB Output is correct
11 Incorrect 12 ms 16000 KB Output isn't correct
12 Incorrect 19 ms 16000 KB Output isn't correct
13 Correct 11 ms 16000 KB Output is correct
14 Incorrect 15 ms 16000 KB Output isn't correct
15 Incorrect 17 ms 16000 KB Output isn't correct
16 Incorrect 23 ms 16000 KB Output isn't correct
17 Incorrect 23 ms 16000 KB Output isn't correct
18 Incorrect 23 ms 16000 KB Output isn't correct
19 Incorrect 23 ms 16000 KB Output isn't correct
20 Incorrect 23 ms 16000 KB Output isn't correct