QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#797981#8363. interactiveL_Wave0 4ms5968kbC++203.2kb2024-12-03 22:17:332024-12-03 22:17:34

Judging History

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

  • [2024-12-03 22:17:34]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:5968kb
  • [2024-12-03 22:17:33]
  • 提交

answer

// Problem: #P13098. 交互题
// Author: XZC(L_Wave)
// Language: Cpp/G++20
// Contest: Hydro
// URL: http://www.nfls.com.cn:10611/p/5472
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// Create Time: not 2024-12-03 20:49:39, but 1926-08-17 11:45:14
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a), i##ABRACADABRA = (b); i <= i##ABRACADABRA; i++)
#define drep(i, a, b) for (int i = (a), i##ABRACADABRA = (b); i >= i##ABRACADABRA; i--)
using namespace std;
using ll = long long;

#ifndef LOCAL
#include"interactive.h"
#else
#include <vector>
#include <cstdio>
#include <cstdlib>

std::vector<int> solve(int n);
int query(std::vector<int> vec);

#define rep0(i, n) rep(i, 0, (n)-1)
#define rep1(i, n) rep(i, 1, (n))
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;
		rep0(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;
	rep0(i, (int)arr.size() - 1) ret += mat[arr[i]][arr[i + 1]];
	cnt ++;
	return ret;
}

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;
		rep0(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);
}
#endif

namespace local{

vector<int>res;
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
int id[505],p[505],n;
long double w[505][505];
bool vis[505];

void dfs(int u){
  // cout<<u<<'\n';
  sort(id+1,id+n+1,[&](int x,int y){
    return w[u][x]>w[u][y];
  });
  res.push_back(u);
  vis[u]=1;
  rep(v,1,n)if (!vis[id[v]]){
    dfs(id[v]);
    return ;
  }
}

int ask(){
  vector<int>Q;
  rep(i,1,n)Q.push_back(p[i]);
  return query(Q);
}

void adj(vector<pair<int,int>>V,long double val){
  long double sum=0;
  for (auto [x,y]:V)sum+=w[x][y];
  sum-=val;
  sum/=V.size();
  for (auto [x,y]:V)w[x][y]-=sum,w[y][x]=w[x][y];
}

std::vector<int> solve(int _n){
  n=_n;
  iota(p+1,p+n+1,1);
  iota(id+1,id+n+1,1);
  rep(i,1,n)rep(j,1,n){
    if (i^j)w[i][j]=2.l/n;
    else w[i][j]=-1e9;
  }
  rep(i,1,8000){
    shuffle(p+1,p+n+1,rng);
    int x=ask();
    if (!x){
      rep(t,1,n-1)w[p[t]][p[t+1]]=w[p[t+1]][p[t]]=-1e9;
      // rep(i,1,n)rep(j,1,n)cout<<w[i][j]<<" \n"[j==n];
      continue;
    }
    vector<pair<int,int>>V;
    rep(t,1,n-1)if (w[p[t]][p[t+1]]>0)V.push_back({p[t],p[t+1]});
    adj(V,x);
    // rep(i,1,n)rep(j,1,n)cout<<w[i][j]<<" \n"[j==n];
  }
  rep(i,1,n){
    int cnt=0;
    rep(j,1,n)cnt+=w[i][j]>0;
    if (cnt==1){
      dfs(i);
      return res;
    }
  }
  return vector<int>(n);
}

}

std::vector<int> solve(int n){return local::solve(n);}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 0ms
memory: 5968kb

input:

1 3
3 1 2

output:

8000 775765009 7113

result:

points 1.0

Test #2:

score: 0
Wrong Answer
time: 4ms
memory: 4024kb

input:

1 30
6 28 10 9 13 4 7 1 21 15 20 27 19 5 17 2 22 12 29 23 14 30 18 3 11 24 26 16 8 25

output:

0 0 0

result:

FAIL WA

Subtask #2:

score: 0
Wrong Answer

Test #11:

score: 90
Accepted
time: 0ms
memory: 5948kb

input:

1 27
17 16 3 20 27 5 2 13 24 21 25 23 19 9 7 4 22 12 26 15 14 11 1 18 6 10 8

output:

8000 775765009 558749364

result:

points 1.0

Test #12:

score: 0
Wrong Answer
time: 4ms
memory: 5892kb

input:

1 29
19 13 20 22 26 1 23 24 3 14 8 25 29 17 10 9 15 11 18 4 2 28 21 7 6 12 16 27 5

output:

0 0 0

result:

FAIL WA