QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#210827 | #5364. 面国漫步 | Liang_Yusong | 0 | 0ms | 0kb | C++14 | 3.2kb | 2023-10-11 20:30:12 | 2023-10-11 20:30:12 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e2+5,K=N*N;
const LL INF=1ll<<60;
int n,k,a[K],m,b[N],pos[N],cnt[N];
LL dis[N];
struct Edge
{
int u,v;
LL w;
};
vector<Edge>ans;
namespace SPJ {
struct atom {
int x;
long long w;
atom(int _x = 0, long long _w = 0) {
x = _x;
w = _w;
}
};
bool SPFA(int *target, int K, int N, vector<Edge> EdgeSet) {
static long long dis[105];
static bool inq[105];
static vector<atom> go[105];
static int q[114514];
for (int i = 0; i < EdgeSet.size(); i++) {
go[EdgeSet[i].u].push_back(atom(EdgeSet[i].v, EdgeSet[i].w));
}
for (int i = 1; i <= N; i++) inq[i] = 0, dis[i] = 1ll << 60;
int t = 1;
q[t] = 1;
dis[1] = 0;
inq[1] = 1;
if (target[1] != 1) return 0;
for (int i = 1; i <= t; i++) {
int x = q[i];
for (auto w : go[x]) {
int y = w.x;
if (dis[y] > dis[x] + w.w) {
dis[y] = dis[x] + w.w;
if (!inq[y]) {
inq[y] = 1;
q[++t] = y;
if (t > K) return 0;
if (q[t] != target[t]) {
return 0;
}
}
}
}
inq[x] = 0;
}
return t == K;
}
}; // namespace SPJ
signed main()
{
freopen("meow.in","r",stdin);
freopen("meow.out","w",stdout);
ios::sync_with_stdio(false),cin.tie(nullptr);
cin>>n>>k;
for(int i=1;i<=k;++i)
cin>>a[i];
for(int i=2;i<=k;++i)
if(a[i]==1||a[i-1]==a[i])
return cout<<"YouAreFake\n",0;
for(int i=1;i<=k;++i)
pos[a[i]]=i;
for(int i=1;i<=k;++i)
if(pos[a[i]]==i)
b[++m]=a[i];
// cout<<"m:"<<m<<"\n";
// cout<<"b:\n";
// for(int i=1;i<=m;++i)
// cout<<b[i]<<" \n"[i==m];
// cout<<"pos:\n";
// for(int i=1;i<=n;++i)
// cout<<pos[i]<<" \n"[i==n];
for(int i=1;i<=m-1;++i)
{
int l=pos[b[i]]+1,r=pos[b[i+1]]-1;
for(int j=l;j<=r;++j)
if(++cnt[a[j]]>=2) // 出点都是 a[l],所以在 SPFA 过程中不可以入两次队
return cout<<"YouAreFake\n",0;
for(int j=l;j<=r;++j)
cnt[a[j]]=0;
}
for(int i=1;i<=n;++i)
dis[i]=INF;
int nowdis=0; // 当前 a[l] 的 dis (吗)
for(int i=1;i<=m-1;++i)
{
int l=pos[b[i]]+1,r=pos[b[i+1]]-1;
for(int j=l;j<=r;++j)
{
--dis[a[j]]; // 想要被更新,距离至少得 -1
ans.push_back({b[i],a[j],dis[a[j]]-nowdis});
}
nowdis+=INF-dis[b[i]];
// cout<<"nowdis: "<<nowdis<<"\n";
// cout<<"dis:\n";
// for(int j=1;j<=n;++j)
// cout<<dis[j]<<" \n"[j==n];
ans.push_back({b[i],b[i+1],INF-dis[b[i]]}); // 不是最优点不更新后面
}
if(SPJ::SPFA(a,k,n,ans))
{
cout<<"YouAreWrite!\n"<<ans.size()<<"\n";
for(auto [u,v,w]:ans)
cout<<u<<" "<<v<<" "<<w<<"\n";
}
else
cout<<"YouAreFake\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
input:
3 1 1
output:
result:
Subtask #2:
score: 0
Dangerous Syscalls
Test #16:
score: 0
Dangerous Syscalls
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:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%