SPJ有误
查看原帖
SPJ有误
249879
chenyilai楼主2021/10/2 20:39

题目要求非负整数KK ,SPJ没有判断 KK 是负数的情况。

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掉的题解:这篇

2021/10/2 20:39
加载中...