結果
| 問題 |
No.990 N×Mマス計算(Kの倍数)
|
| コンテスト | |
| ユーザー |
MarcusAureliusAntoninus
|
| 提出日時 | 2020-02-14 22:04:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,019 bytes |
| コンパイル時間 | 2,042 ms |
| コンパイル使用メモリ | 205,548 KB |
| 最終ジャッジ日時 | 2025-01-09 00:13:37 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 15 TLE * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:23: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 4 has type ‘int64_t*’ {aka ‘long int*’} [-Wformat=]
18 | scanf("%d%d%lld %c", &N, &M, &K, &op);
| ~~~^ ~~
| | |
| long long int* int64_t* {aka long int*}
| %ld
main.cpp:21:27: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘long int*’ [-Wformat=]
21 | scanf("%lld", &e);
| ~~~^ ~~
| | |
| | long int*
| long long int*
| %ld
main.cpp:23:27: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘long int*’ [-Wformat=]
23 | scanf("%lld", &e);
| ~~~^ ~~
| | |
| | long int*
| long long int*
| %ld
main.cpp:55:20: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int64_t’ {aka ‘long int’} [-Wformat=]
55 | printf("%lld\n", ans);
| ~~~^ ~~~
| | |
| | int64_t {aka long int}
| long long int
| %ld
main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
18 | scanf("%d%d%lld %c", &N, &M, &K, &op);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:21:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared w
ソースコード
#include <bits/stdc++.h>
int64_t calcGCD(int64_t a, int64_t b)
{
while (a)
{
b %= a;
std::swap(a, b);
}
return b;
}
int main()
{
int N, M;
int64_t K;
char op;
scanf("%d%d%lld %c", &N, &M, &K, &op);
std::vector<int64_t> A(N), B(M);
for (auto& e: B)
scanf("%lld", &e);
for (auto& e: A)
scanf("%lld", &e);
int64_t ans{};
if (op == '+')
{
std::map<int64_t, int64_t> rest_a, rest_b;
for (auto& e: A)
rest_a[e % K]++;
for (auto& e: B)
rest_b[e % K]++;
for (auto& e: rest_a)
ans += e.second * rest_b[K - e.first];
ans += rest_a[0] * rest_b[0];
}
else
{
std::map<int64_t, int64_t> gcd_a, gcd_b;
for (auto& e: A)
gcd_a[calcGCD(e, K)]++;
for (auto& e: B)
gcd_b[calcGCD(e, K)]++;
for (int64_t i{1}; i * i <= K; i++)
if (K % i == 0)
gcd_b[i] += 0;
for (auto& e: gcd_b)
for (int64_t i{2 * e.first}; i <= K; i += e.first)
gcd_b[e.first] += gcd_b[i];
for (auto& e: gcd_a)
ans += e.second * gcd_b[K / e.first];
}
printf("%lld\n", ans);
return 0;
}
MarcusAureliusAntoninus