結果
| 問題 |
No.887 Collatz
|
| コンテスト | |
| ユーザー |
tko919
|
| 提出日時 | 2019-09-21 16:26:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 855 bytes |
| コンパイル時間 | 1,500 ms |
| コンパイル使用メモリ | 164,824 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-19 01:39:27 |
| 合計ジャッジ時間 | 2,512 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 WA * 1 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:27:11: warning: 'maxx' may be used uninitialized [-Wmaybe-uninitialized]
27 | printf("%d",maxx);
| ~~~~~~^~~~~~~~~~~
main.cpp:19:17: note: 'maxx' was declared here
19 | int n,cnt=0,maxx; scanf("%d",&n);
| ^~~~
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end
int main(){
int n,cnt=0,maxx; scanf("%d",&n);
while(n!=1){
chmax(maxx,n);
if(n&1)n=3*n+1;
else n/=2;
cnt++;
}
printf("%d\n",cnt);
printf("%d",maxx);
return 0;
}
tko919