QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#751606#8363. interactive2022zyCompile Error//C++142.7kb2024-11-15 19:41:072024-11-15 19:41:08

Judging History

你现在查看的是最新测评结果

  • [2024-11-15 19:41:08]
  • 评测
  • [2024-11-15 19:41:07]
  • 提交

answer

#include "interactive.h"
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
using namespace std;

namespace
{
	const int MAXN = 500, MAXQ = 300000;
	int n, p[505], mat[505][505], cnt;
	bool vis[505];
	bool legal(const vector<int>& arr)
	{
		if((int)arr.size() != n) return false;
		rep1(i, n) vis[i] = false;
		rep(i, arr.size()) {
			if(arr[i] < 1 || arr[i] > n || vis[arr[i]]) return false;
			vis[arr[i]] = true;
		}
		return true;
	}
}

int query(vector<int> arr)
{
	if(cnt == MAXQ || !legal(arr)) {
		printf("WA: 0\n"); exit(0);
	}
	
	int ret = 0;
	rep(i, (int)arr.size() - 1) ret += mat[arr[i]][arr[i + 1]];
	cnt ++;
	return ret;
}


template<class I>I min(I x,I y){return x<y?x:y;}
template<class I>I max(I x,I y){return x>y?x:y;}
template<class I>I abs(I x){return x>0?x:-x;}
template<class I>void swap(I &x,I &y){I z=x;x=y;y=z;return;}

const int N=505;
std::vector<int>a;
bool b[N][N];
int link[N][2];
int cntb,sm1,sm2,ls;
void insert(int x,int y){
	if(b[x][y])return;
	link[x][link[x][0]?1:0]=y;
	link[y][link[y][0]?1:0]=x;
	b[x][y]=b[y][x]=1;cntb++;
	return;
}
int he;
std::vector<int>solve(int n){
	for(int i=1;i<=n;i++)a.push_back(i);
	for(int i=1;i<=n;i++){
		if(link[i][1])continue;
		for(int j=i+1;j<=n;j++){
			if(link[j][1])continue;
			for(int k=j+1;k<=n;k++){
				if(link[k][1])continue;
				ls=3;
				for(int p=1;p<=n;p++){
					if(p==i||p==j||p==k)continue;
					a[ls]=p;ls++;
				}
				a[0]=i;a[1]=j;a[2]=k;
				sm1=query(a);
				a[0]=j;a[1]=i;
				sm2=query(a);
				if(sm1==sm2){
					if(b[j][k]||b[i][k]){
						insert(j,k);
						insert(i,k);
					}
					else{
						a[0]=j;a[1]=k;a[2]=i;
						sm1=query(a);
						a[0]=k;a[1]=j;
						sm2=query(a);
						if(sm1>sm2)insert(k,i),insert(j,k);
						else insert(j,i);
					}
				}
				else{
					if(sm1>sm2)insert(j,k);
					else insert(i,k);
					a[0]=j;a[1]=k;a[2]=i;
					sm1=query(a);
					a[0]=k;a[1]=j;
					sm2=query(a);
					if(sm1>sm2)insert(k,i);
					else if(sm2>sm1)insert(j,i);
					else if(b[k][i])insert(j,i);
				}
				if(cntb==n-1)break;
			}
			if(cntb==n-1)break;
		}
		if(cntb==n-1)break;
	}
	
	for(int i=1;i<=n;i++){
		if(link[i][1]==0)he=i;
	}
	for(int i=1;i<=n;i++){
		a[i-1]=he;
		if(i>=2&&link[he][0]==a[i-2])he=link[he][1];
		else he=link[he][0];
	}
	
	return a;
}

int main()
{
	scanf("%d", &n);
	rep1(i, n) scanf("%d", &p[i]);
	rep1(i, n - 1) mat[p[i]][p[i + 1]] = mat[p[i + 1]][p[i]] = 1;
	
	vector<int> ans = solve(n);
	if(!legal(ans)) printf("WA: 1\n");
	else {
		int sum = 0;
		rep(i, n - 1) sum += mat[ans[i]][ans[i + 1]];
		if(sum == n - 1) printf("AC: %d\n", cnt);
		else printf("WA: 1\n");
	}
	exit(0);
}

Details

implementer.cpp: In function ‘int main()’:
implementer.cpp:39:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   39 |         scanf("%*d%d", &n);
      |         ~~~~~^~~~~~~~~~~~~
implementer.cpp:40:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |         rep1(i, n) scanf("%d", &p[i]);
      |                    ~~~~~^~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:117:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  117 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
answer.code:118:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  118 |         rep1(i, n) scanf("%d", &p[i]);
      |                    ~~~~~^~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccDsc0W8.o: in function `query(std::vector<int, std::allocator<int> >)':
answer.code:(.text+0xf0): multiple definition of `query(std::vector<int, std::allocator<int> >)'; /tmp/ccutx7i9.o:implementer.cpp:(.text+0x80): first defined here
/usr/bin/ld: /tmp/ccDsc0W8.o: in function `main':
answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/ccutx7i9.o:implementer.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status