結果
| 問題 |
No.990 N×Mマス計算(Kの倍数)
|
| コンテスト | |
| ユーザー |
edamame882
|
| 提出日時 | 2020-02-14 22:42:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,359 bytes |
| コンパイル時間 | 1,938 ms |
| コンパイル使用メモリ | 179,576 KB |
| 実行使用メモリ | 264,100 KB |
| 最終ジャッジ日時 | 2024-11-16 01:04:37 |
| 合計ジャッジ時間 | 12,275 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 WA * 7 TLE * 3 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
//container util
#define all(x) (x).begin(),(x).end()
//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};
//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
// Mod int
const int mod = 1000000007;
struct mint {
ll x;
mint():x(0){}
mint(ll x):x((x%mod+mod)%mod){}
// mint(ll x):x(x){}
mint& fix() { x = (x%mod+mod)%mod; return *this;}
mint operator-() const { return mint(0) - *this;}
mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
mint operator+(const mint& a)const{ return mint(*this) += a;}
mint operator-(const mint& a)const{ return mint(*this) -= a;}
mint operator*(const mint& a)const{ return mint(*this) *= a;}
bool operator<(const mint& a)const{ return x < a.x;}
bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
typedef vector<mint> vm;
typedef vector<vm> vvm;
//
ll modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
long long gcd( long long m, long long n ){
if ( n == 0) return m;
return gcd(n,m%n);
}//最大公約数
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
char cmd;
int n,m;
ll k;
cin >> m >> n >> k;
cin >> cmd;
VLL x(n);
VLL y(m);
rep(i,n) cin >> x[i];
rep(i,m) cin >> y[i];
map<ll,ll> mpx;
map<ll,ll> mpy;
rep(i,n) mpx[x[i]%k]++;
rep(j,m) mpy[y[j]%k]++;
if(cmd == '+'){
ll ans = 0;
for(auto x: mpx){
ll less = k-x.first;
ans += x.second * mpy[less];
}
cout << ans << endl;
}else{
ll ans = 0;
for(auto x: mpx){
// cout << x.first << " ,add ";
if(x.first == 0){
// cout << x.second * m << endl;
ans += x.second * m;
}else{
ll gcdNum = gcd(k,x.first);
if(gcdNum == 1){
ll inv = modinv(x.first,k);
// cout << x.second * mpy[inv] << " inv " << inv << endl;
ans += x.second * mpy[inv];
}else{
ll less = k / gcdNum;
ll cnt = 0;
while(cnt < k){
ans += x.second * mpy[cnt];
cnt += less;
}
}
}
}
cout << ans << endl;
}
// rep(i,12) cout << modinv(i,12) << " ";
// cout << endl;
// rep(j,m) {
// rep(i,n){
// cout << x[i] * y[j] % k << " ";
// }
// cout << endl;
// }
return 0;
}
edamame882