Submission #79963
ソースコード
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 | #include<bits/stdc++.h> using namespace std; #define int long long main(){ // 入力 long long n,k; cin>>n>>k; long long a[n]; for ( int i=0;i<n;i++){ cin>>a[i]; } /* ans : 答え(数列の長さの最小値) now : 今の(l:r]の和 l,r : 数列の左右端 */ long long ans=n+1,now=0,r=0; for ( int l=0;l<n;l++){ while (now<k && r<n && now+a[r]>=0){ now+=a[r]; r++; } if (now>=k){ ans=min(ans,r-l); } if (l==r){ now+=a[r]; r++; } now-=a[l]; } //もしansがn+1のままなら条件を満たす区間は無い if (ans==n+1){ ans=-1; } cout<<ans<< "\n" ; } |
ステータス
項目 | データ |
---|---|
問題 | 1816 - しゃくとり! |
ユーザー名 | ei2326 |
投稿日時 | 2024-07-17 23:42:44 |
言語 | C++17 |
状態 | Accepted |
得点 | 1 |
ソースコード長 | 789 Byte |
最大実行時間 | 49 ms |
最大メモリ使用量 | 1384 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 1 / 1 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in1.txt | AC | 30 ms | 604 KB |
1
|
in2.txt | AC | 48 ms | 1296 KB |
1
|
in3.txt | AC | 49 ms | 1384 KB |
1
|
in4.txt | AC | 32 ms | 1352 KB |
1
|
in5.txt | AC | 37 ms | 1312 KB |
1
|
in6.txt | AC | 17 ms | 508 KB |
1
|
in7.txt | AC | 24 ms | 484 KB |
1
|
in8.txt | AC | 44 ms | 1224 KB |
1
|
in9.txt | AC | 21 ms | 420 KB |
1
|
in10.txt | AC | 17 ms | 448 KB |
1
|
in11.txt | AC | 48 ms | 1188 KB |
1
|
in12.txt | AC | 24 ms | 772 KB |
1
|
in13.txt | AC | 36 ms | 1208 KB |
1
|
in14.txt | AC | 42 ms | 1308 KB |
1
|
in15.txt | AC | 36 ms | 1152 KB |
1
|