Submission #00008
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #include<bits/stdc++.h> using namespace std; int n,k; int f; int dat[100005]; int main(){ cin >> n >> k; for ( int i = 0; i < k; i++){ int a; cin >> a; if (a != 0){ dat[i] = a; } else { dat[i] = 1000000; f = 1; } } sort(dat,dat + k); /* for(int i = 0; i < k; i++){ cout << dat[i] << " "; } cout << endl; */ int cnt,becnt; cnt = becnt = 1; int ans = 0; for ( int i = 1; i < k; i++){ if (dat[i - 1] + 1 != dat[i]){ // cout << dat[i] << " " << cnt << " " << dat[i - cnt] << " " << dat[i - cnt - 1] << endl; if (f && dat[i - cnt] - dat[i - cnt - 1] == 2){ ans = max(ans,cnt + becnt + 1); } else { ans = max(ans,cnt); } becnt = cnt; cnt = 1; } else { cnt++; } } if (f == 0){ ans = max(ans,cnt); } cout << ans << endl; } |
ステータス
項目 | データ |
---|---|
問題 | 0002 - 最長の階段 |
ユーザー名 | ei1501 |
投稿日時 | 2017-02-03 16:34:13 |
言語 | C++11 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 934 Byte |
最大実行時間 | 44 ms |
最大メモリ使用量 | 788 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | set1 | 20 / 20 | *in1 |
2 | set2 | 20 / 20 | *in[12] |
3 | set3 | 20 / 20 | *in[123] |
4 | set4 | 20 / 20 | *in[1234] |
5 | set5 | 20 / 20 | *in[12345] |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # | ||||
---|---|---|---|---|---|---|---|---|
2007-ho-t2-in1 | AC | 17 ms | 476 KB |
1
|
2
|
3
|
4
|
5
|
2007-ho-t2-in2 | AC | 14 ms | 456 KB |
2
|
3
|
4
|
5
|
|
2007-ho-t2-in3 | AC | 32 ms | 688 KB |
3
|
4
|
5
|
||
2007-ho-t2-in4 | AC | 44 ms | 732 KB |
4
|
5
|
|||
2007-ho-t2-in5 | AC | 42 ms | 788 KB |
5
|