题目要求非负整数K ,SPJ没有判断 K 是负数的情况。
hack数据:
12
0 1 3 -1 1 -1 1 -1 1 -1 1 -1
错误输出:
6
-1
正确输出
2
1
修改后
#include "testlib.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=2e6+5;
int n;
ll a[M];
int main(int argc, char* argv[])
{
registerTestlibCmd(argc, argv);
n=inf.readInt();
for(int i=1;i<=n;i++)
a[i]=inf.readLong();
int of=ouf.readInt(),af=ans.readInt();
int tk=ouf.readInt(),ak=ans.readInt();
if(of!=af)
quitf(_wa, "Wrong answer on column 1: expected = %d, found = %d", af, of);
else
{
int cnt=1;ll now=a[1];
for(int i=2;i<=n;i++)
{
if(a[i]>a[i-1])now+=tk;
else if(a[i]<a[i-1])now-=tk;
if(now==a[i])cnt++;
}
if(cnt!=of||tk<0)
quitf(_wa, "Wrong answer on column 2");
else quitf(_ok, "Accepted");
}
}
hack掉的题解:这篇。