結果
| 問題 |
No.887 Collatz
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-29 21:57:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,789 bytes |
| コンパイル時間 | 1,906 ms |
| コンパイル使用メモリ | 196,708 KB |
| 最終ジャッジ日時 | 2025-01-07 19:54:35 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:81:17: warning: ‘i’ may be used uninitialized [-Wmaybe-uninitialized]
81 | ++i;
| ^~~
main.cpp:73:15: note: ‘i’ was declared here
73 | ll n, i, nn;
| ^
In file included from /usr/include/c++/13/istream:41,
from /usr/include/c++/13/sstream:40,
from /usr/include/c++/13/complex:45,
from /usr/include/c++/13/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
from main.cpp:1:
In member function ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’,
inlined from ‘int main()’ at main.cpp:84:23:
/usr/include/c++/13/ostream:204:25: warning: ‘nn’ may be used uninitialized [-Wmaybe-uninitialized]
204 | { return _M_insert(__n); }
| ~~~~~~~~~^~~~~
main.cpp: In function ‘int main()’:
main.cpp:73:18: note: ‘nn’ was declared here
73 | ll n, i, nn;
| ^~
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n) n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;
ll mod_pow(ll a, ll b) {
ll res = 1, mul = a;
for (int i = 0; i < 31; ++i) {
if (b >> i & 1) {
res *= mul;
res %= MOD;
}
mul = (mul * mul) % MOD;
}
return res;
}
void addedge(int from, int to, int cost) {
G[from].push_back({ to,cost });
G[to].push_back({ from,cost });
}
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
for (auto& e : t) fill_v(e, v);
}
template<typename T>
void outp(vector<T>v) {
for (int i = 0; i < v.size(); ++i) {
cout << v[i];
if (i != v.size() - 1) { cout << " "; }
}
}
double add(double a, double b) {
if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
return a + b;
}
ll f(ll n) {
if (n % 2) { return 3 * n + 1; }
return n / 2;
}
int main() {
ll n, i, nn;
bool bigger;
cin >> n;
while (n != 1) {
bigger = 0;
if (n % 2) { bigger = 1; }
n = f(n);
if (bigger) { nn = n; }
++i;
}
cout << i << endl << nn << endl;
}