結果
問題 | No.1868 Teleporting Cyanmond |
ユーザー |
|
提出日時 | 2022-03-11 22:03:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 505 bytes |
コンパイル時間 | 185 ms |
コンパイル使用メモリ | 28,288 KB |
最終ジャッジ日時 | 2025-01-28 08:39:55 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 25 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:5:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 5 | scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:7:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 7 | for(int i = 0; i < N-1; ++i) scanf("%d", R + i); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include<cstdio>template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }int main(){int N;scanf("%d", &N);int R[N-1];for(int i = 0; i < N-1; ++i) scanf("%d", R + i);int left = 0, right, answer = 0, mx = R[0]-1;while(left < N-1){answer++;if(mx == N-1) break;right = mx;while(left < right && left < N-1){left++;chmax(mx, R[left]-1);}}printf("%d\n", answer);}