結果
| 問題 |
No.1047 Zero (Novice)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-08 23:09:06 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,532 bytes |
| コンパイル時間 | 1,832 ms |
| コンパイル使用メモリ | 181,228 KB |
| 実行使用メモリ | 133,280 KB |
| 最終ジャッジ日時 | 2024-07-04 01:09:53 |
| 合計ジャッジ時間 | 5,457 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 WA * 1 TLE * 1 -- * 2 |
ソースコード
// #define DEBUG_ON
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define timer_start() \
chrono::system_clock::time_point start, end; \
start = chrono::system_clock::now();
#define timer_wrap() \
end = chrono::system_clock::now(); \
double time = static_cast<double>( \
chrono::duration_cast<chrono::microseconds>(end - start).count() / \
1000.0); \
printf("time %lf[ms]\n", time); \
start = end;
#define optimize_cin() \
cin.tie(0); \
ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
#define INF 1000000000 // 10^9
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int main() {
// input
int a, b;
cin >> a >> b;
#ifdef DEBUG_ON
timer_start();
#endif
if ((a > 0 && b > 0) || (a < 0 && b < 0)) {
cout << -1 << endl;
return 0;
}
ll n = 0;
int d = 0;
set<ll> already;
do {
d++;
n = (a * n) + b;
if (already.count(n) > 0) {
// if (true) {
cout << -1 << endl;
return 0;
}
already.insert(n);
} while (n != 0);
cout << d << endl;
#ifdef DEBUG_ON
timer_wrap();
#endif
return 0;
}