Submission #778473

# Submission time Handle Problem Language Result Execution time Memory
778473 2023-07-10T10:57:43 Z I_Love_EliskaM_ Toy Train (IOI17_train) C++14
5 / 100
5 ms 980 KB
#include "train.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define ll long long

vector<int> p1(vector<int>a,vector<int>r,vector<int>u,vector<int>v) {
	int n=a.size(), m=u.size();
	vector<int> s(n);
	vector<int> f(n);
	vector<int> ans(n);
	forn(i,m) if (u[i]==v[i]) s[u[i]]=1;
	forn(i,m) if (u[i]!=v[i]) f[u[i]]=1;
	int now=0;
	for (int i=n-1; i>=0; --i) {
		if (s[i]) {
			if (now) {
				if (!a[i]) {
					if (!r[i]) now=0;
				} else {
					if (f[i]) now=1;
					else now = r[i];
				}
			} else {
				if (a[i]) {
					if (r[i]) now=1;
				} else {
					if (f[i]) now=0;
					else now = r[i];
				}
			}
		}
		ans[i]=now;
	}
	return ans;
}

const int N=5555;
vector<int> adj[N];
int vis[N];
int ok[N];
int dfs(int u) {
	if (vis[u]==1) return 1;
	if (vis[u]==2) return 0;
	vis[u]=1;
	int z=0;
	for(auto&v:adj[u]) z|=dfs(v);
	vis[u]=2;
	return z;
}
int dfs2(int u) {
	if (ok[u]) return 1;
	if (vis[u]) return 0;
	vis[u]=1;
	int z=0;
	for(auto&v:adj[u]) z|=dfs2(v);
	return z;
}
vector<int> p3(vector<int>a,vector<int>r,vector<int>u,vector<int>v) {
	int n=a.size(), m=u.size();
	vector<int> ans(n);
	vector<int> ok(n);
	forn(i,m) adj[u[i]].pb(v[i]);
	forn(i,n) if (r[i]) {
		forn(j,n) vis[i]=0;
		int q=dfs(i);
		ok[i]=q;
	}
	forn(i,n) {
		forn(j,n) vis[j]=0;
		int q=dfs2(i);
		ans[i]=q;
	}
	return ans;
}

vector<int> p4(vector<int>a,vector<int>r,vector<int>u,vector<int>v) {
	int n=a.size(), m=u.size();
	vector<int> s(n);
	vector<int> ans(n);
	forn(i,m) if (u[i]==v[i]) s[i]=1;
	int now;
	for (int i=n-1; i>=0; --i) {
		if (s[i]) now=a[i];
		ans[i]=now;
	}
	return ans;
}

vector<int> who_wins(vector<int>a,vector<int>r,vector<int>u,vector<int>v) {

	int n=a.size(), m=u.size();
	int z=1;
	forn(i,m) z&=(u[i]==v[i]) || (v[i]==(u[i]+1));
	if (z) {
		return p1(a,r,u,v);
	}
	return vector<int>(n,0);
	z=1;
	forn(i,n) z&=a[i];
	if (z) return p3(a,r,u,v);
	forn(i,n) z|=a[i];
	if (!z) return p4(a,r,u,v);

}

Compilation message

train.cpp: In function 'std::vector<int> p4(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:86:9: warning: 'now' may be used uninitialized in this function [-Wmaybe-uninitialized]
   86 |   ans[i]=now;
# Verdict Execution time Memory Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 3 ms 832 KB Output is correct
3 Correct 3 ms 832 KB Output is correct
4 Correct 3 ms 836 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 3 ms 832 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 3 ms 852 KB Output is correct
9 Correct 3 ms 744 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 3 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 980 KB Output is correct
2 Correct 4 ms 980 KB Output is correct
3 Correct 4 ms 960 KB Output is correct
4 Incorrect 4 ms 968 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 852 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 980 KB 3rd lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 852 KB Output is correct
2 Correct 3 ms 832 KB Output is correct
3 Correct 3 ms 832 KB Output is correct
4 Correct 3 ms 836 KB Output is correct
5 Correct 3 ms 852 KB Output is correct
6 Correct 3 ms 832 KB Output is correct
7 Correct 3 ms 980 KB Output is correct
8 Correct 3 ms 852 KB Output is correct
9 Correct 3 ms 744 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 3 ms 740 KB Output is correct
12 Incorrect 1 ms 340 KB 3rd lines differ - on the 2nd token, expected: '1', found: '0'
13 Halted 0 ms 0 KB -