QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#726083#5423. Perfect MatchingCode_quantumCompile Error//C++141.8kb2024-11-08 21:33:232024-11-08 21:33:24

Judging History

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

  • [2024-11-08 21:33:24]
  • 评测
  • [2024-11-08 21:33:23]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define px first
#define py second
#define pb push_back

const int N = 200005;
int n, res, a[N], d[N], barl[N], barr[N];
map<int, int> mpl, mpr;
vector<pii> g[N], ans; vector<int> tmp[N]; bool vis[N];

int dfs(int u, int fa){
	vis[u] = true; res += d[u]; tmp[u].clear();
	for(auto now: g[u]){
		int v = now.px, id = now.py;
		if(v == fa) continue;
		if(vis[v]){
			tmp[u].pb(id); continue;
		}
		int gt = dfs(v); tmp[u].pb(id);
		if(gt) tmp[u].pb(gt);
	}
	while((int)tmp[u].size() > 1){
		int x = tmp[u].back(); tmp[u].pop_back();
		int y = tmp[u].back(); tmp[u].pop_back();
		ans.pb({x, y});
	}
	if((int)tmp[u].size() & 1){
		return tmp[u].back();
	}
	return 0;
}
void work(){
	scanf("%d", &n); int cntl = 0, cntr = 0; 
	mpl.clear(); mpr.clear(); ans.clear();
	for(int i = 1; i <= n; i ++){
		scanf("%d", &a[i]);
		barl[++ cntl] = a[i] + i;
		barr[++ cntr] = a[i] - i;
	}
	sort(barl + 1, barl + cntl + 1);
	cntl = unique(barl + 1, barl + cntl + 1) - barl - 1;
	sort(barr + 1, barr + cntr + 1);
	cntr = unique(barr + 1, barr + cntr + 1) - barr - 1;
	for(int i = 1; i <= cntl; i ++) mpl[barl[i]] = i;
	for(int i = 1; i <= cntr; i ++) mpr[barr[i]] = i;
	for(int i = 1; i <= cntl + cntr; i ++){
		g[i].clear(); d[i] = 0; vis[i] = false;
	}
	for(int i = 1; i <= n; i ++){
		int x = mpl[a[i] + i], y = mpr[a[i] - i] + cntl;
		g[x].pb({y, i}); g[y].pb({x, i}); d[x] ++; d[y] ++; 
	}
	for(int i = 1; i <= cntl + cntr; i ++) if(! vis[i]){
		res = 0; dfs(i, 0); if((res / 2) & 1){puts("No"); return;}
	}
	puts("Yes");
	assert(ans.size() <= n / 2);
	for(auto now: ans) printf("%d %d\n", now.px, now.py);
}
int main(){
	int t; scanf("%d", &t);
	while(t --) work(); return 0;
} 

詳細信息

answer.code: In function ‘int dfs(int, int)’:
answer.code:21:29: error: too few arguments to function ‘int dfs(int, int)’
   21 |                 int gt = dfs(v); tmp[u].pb(id);
      |                          ~~~^~~
answer.code:13:5: note: declared here
   13 | int dfs(int u, int fa){
      |     ^~~
answer.code: In function ‘void work()’:
answer.code:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   35 |         scanf("%d", &n); int cntl = 0, cntr = 0;
      |         ~~~~~^~~~~~~~~~
answer.code:38:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |                 scanf("%d", &a[i]);
      |                 ~~~~~^~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:63:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   63 |         int t; scanf("%d", &t);
      |                ~~~~~^~~~~~~~~~