結果
| 問題 |
No.990 N×Mマス計算(Kの倍数)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-14 23:07:22 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,862 bytes |
| コンパイル時間 | 1,008 ms |
| コンパイル使用メモリ | 130,788 KB |
| 実行使用メモリ | 18,572 KB |
| 最終ジャッジ日時 | 2024-11-30 16:23:44 |
| 合計ジャッジ時間 | 8,744 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 11 WA * 6 TLE * 2 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
using int64 = long long;
using P = pair<int64,int64>;
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
int64 n,m,k;
cin >> n >> m >> k;
char op; cin >> op; bool plus = op == '+';
vector<int64> a(n);
vector<int64> b(m);
for (int64 i=0; i<m; i++) {
cin >> b[i];
b[i] %= k;
}
for (int64 i=0; i<n; i++) {
cin >> a[i];
a[i] %= k;
}
sort(b.begin(), b.end());
sort(a.begin(), a.end());
vector<P> la; la.emplace_back(a[0],0);
for (int64 i=0; i<n; i++) {
if (la.back().first == a[i]) la.back().second++;
else la.emplace_back(a[i], 1);
}
vector<P> lb; lb.emplace_back(b[0],0);
for (int64 i=0; i<m; i++) {
if (lb.back().first == b[i]) lb.back().second++;
else lb.emplace_back(b[i], 1);
}
//
// for (auto [ai, ac] : la) cout << ai << " " << ac << endl;
// for (auto [bi, bc] : lb) cout << bi << " " << bc << endl;
int64 ans = 0;
if (plus) {
for (auto [ai, ac] : la) {
auto it = lower_bound(lb.begin(), lb.end(), P(k-ai,0) );
if (it == lb.end()) continue;
auto [bi, bc] = *it;
if (bi == k - ai) ans += ac * bc;
}
} else {
if (la[0].first == 0) ans += la[0].second * m;
if (lb[0].first == 0) ans += lb[0].second * n;
for (auto [ai, ac] : la) {
if (ai == 0) continue;
int64 s = k / gcd(k, ai);
for (int j = s; j < k; j += s) {
auto it = lower_bound(lb.begin(), lb.end(), P(j, 0));
if (it == lb.end()) continue;
auto[bi, bc] = *it;
if (bi == j) ans += ac * bc;
}
}
}
cout << ans << endl;
}