QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#210411#5364. 面国漫步yyandy0 1ms4076kbC++141.8kb2023-10-11 14:00:112023-10-11 14:00:11

Judging History

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

  • [2023-10-11 14:00:11]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:4076kb
  • [2023-10-11 14:00:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N=10100;
int n,K,A[N],vis[N],b[N];
vector<pair<int,ll> > vec[N];
struct E {
	int x,y;
	ll w;
};
vector<E> edge;
namespace checker {
	ll dis[N];
	bool inq[N];
	inline vector<int> SPFA(int n) {
		vector<int> ans;
		queue<int> q;
		q.push(1);
		for(int i=1;i<=n;++i)
			dis[i]=1ll<<60;
		memset(inq,0,sizeof(inq));
		dis[1]=0;
		inq[1]=1;
		ans.push_back(1);
		while(!q.empty()) {
			int x=q.front();
			q.pop();
			inq[x]=0;
			for(auto i:vec[x]) {
				if(dis[i.first]>dis[x]+i.second) {
					dis[i.first]=dis[x]+i.second;
					if(!inq[i.first]) {
						q.push(i.first);
						ans.push_back(i.first);
						inq[i.first]=1;
					}
				}
			}
		}
		return ans;
	}
}
mt19937 rnd(time(0));
ll fun[100000];
int main() {
//	freopen("5_4.in","r",stdin);
//	freopen("meow.out","w",stdout);
	cin>>n>>K;
	for(int i=1; i<=K; ++i)
		cin>>A[i],vis[A[i]]++;
	for(int i=1; i<=n; ++i)
		b[i]=vis[i];
	if(A[1]!=1||vis[1]>1)cout<<"No\n",exit(0);
	memset(vis,0,sizeof(vis));
	ll inf=1ll<<60,tot=0;
	for(int i=2,lst=2,lstb=1; i<=K+1; ++i) {
		b[A[i]]--;
		if(!b[A[i]]){
			// distance to  
			for(int j=lst;j<i;++j)
				if(b[A[j]])
					edge.push_back((E){lstb,A[j],inf-tot-max(fun[A[j]],fun[lstb])-1}),fun[A[j]]=max(fun[A[j]],fun[lstb])+1;
				else edge.push_back((E){lstb,A[j],fun[lstb]});
			//fun [x] x to y smst dis
			tot+=fun[lstb];
			edge.push_back((E){lstb,A[i],fun[lstb]});
			lst=i+1;lstb=A[i];
		}
	}
	for(auto i:edge) vec[i.x].push_back(make_pair(i.y,i.w));
	auto P=checker::SPFA(n);
	int totc=1;
	if(P.size()!=K)cout<<"No\n",exit(0);
	for(int i:P) {
		if(i!=A[totc])cout<<"No\n",exit(0);
		totc++;
	}
	
	cout<<"Yes\n";
	cout<<edge.size()<<endl;
	for(auto i:edge) {
		cout<<i.x<<' '<<i.y<<' '<<i.w<<endl;
	}
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4004kb

input:

3 1
1

output:

Yes
0

result:

wrong answer Wrong Answer on the First line of output

Subtask #2:

score: 0
Wrong Answer

Test #16:

score: 0
Wrong Answer
time: 1ms
memory: 4076kb

input:

85 78
1 46 49 66 12 47 36 28 44 17 48 34 5 82 20 40 69 52 75 27 14 43 53 83 33 55 38 77 58 56 76 81 6 84 19 80 67 3 50 25 26 21 29 62 70 22 68 63 74 37 7 73 78 42 32 2 64 8 39 71 59 18 23 24 9 51 85 11 57 41 45 16 54 30 35 61 72 4

output:

Yes
77
1 46 0
46 49 0
49 66 0
66 12 0
12 47 0
47 36 0
36 28 0
28 44 0
44 17 0
17 48 0
48 34 0
34 5 0
5 82 0
82 20 0
20 40 0
40 69 0
69 52 0
52 75 0
75 27 0
27 14 0
14 43 0
43 53 0
53 83 0
83 33 0
33 55 0
55 38 0
38 77 0
77 58 0
58 56 0
56 76 0
76 81 0
81 6 0
6 84 0
84 19 0
19 80 0
80 67 0
67 3 0
3 5...

result:

wrong answer Wrong Answer on the First line of output

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%