QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#414159 | #7866. Teleportation | chuchu | WA | 1ms | 4176kb | C++20 | 836b | 2024-05-18 16:09:19 | 2024-05-18 16:09:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define range(x) (x).begin(),(x).end()
const int dir[][2]={1,0,-1,0,0,1,0,-1};
const int N=100005;
int dp[N];
void solve()
{
memset(dp,0x3f,sizeof dp);
int n,x;
cin>>n>>x;
vector<int>a(n);
for(auto& c:a)
cin>>c;
dp[x]=x;
int ans=0;
if(a[0]>x){
ans+=n-a[0];
a[0]=0;
}
for(int i=x-1;~i;--i){
if(i+a[i]<=x)
dp[i]=dp[i+max(a[i],1)]-i-a[i]+1;
dp[i]+=i;
if(i)
dp[i]=min(dp[i],dp[i+1]);
}
cout<<ans+dp[0]<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4176kb
input:
4 3 0 1 2 3
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3964kb
input:
4 3 0 0 0 0
output:
4
result:
ok 1 number(s): "4"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3956kb
input:
4 3 2 2 2 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3900kb
input:
2 1 0 0
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 1ms
memory: 4120kb
input:
2 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3956kb
input:
300 25 182 9 13 211 258 132 27 42 218 200 271 258 164 121 8 84 29 195 141 290 110 0 272 93 142 134 140 32 232 99 162 199 297 287 212 29 182 53 61 98 116 282 75 245 230 165 22 4 179 89 274 231 46 299 248 208 200 285 221 50 221 199 294 241 195 138 22 204 113 100 132 276 158 146 238 178 100 94 131 157 ...
output:
129
result:
wrong answer 1st numbers differ - expected: '10', found: '129'