Submission #390125

# Submission time Handle Problem Language Result Execution time Memory
390125 2021-04-15T11:41:35 Z mehrdad_sohrabi Toy Train (IOI17_train) C++14
23 / 100
352 ms 1868 KB
#include <bits/stdc++.h>
#include "train.h"
/// 500 485 462 A4
using namespace std;
typedef long long int ll;
typedef complex<double> point;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
//#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
const int N=5e3+10,inf=(ll)1e15;
ll vis[N];
ll t[N];
vector <int> g[N],in[N];
std::vector<int32_t> who_wins(std::vector<int32_t> A, std::vector<int32_t> R, std::vector<int32_t> U, std::vector<int32_t> V) {
	ll n=A.size(),m=U.size();
	for (int i=0;i<U.size();i++){
        g[U[i]].pb(V[i]);
        in[V[i]].pb(U[i]);
	}
	while(true){
        queue <int> q;
        for (int i=0;i<n;i++){
            t[i]=g[i].size();
            if (vis[i]==0 && R[i]==1){
                q.push(i);
            }
        }
        while(q.size()){
            ll v=q.front();
            t[v]=0;
            q.pop();
            for (auto u : in[v]){
              //  cout << u << " " << v << " " << A[u] << " " << t[u] << endl;
                if (A[u]==1 && t[u]!=0){
                    t[u]=0;
                    q.push(u);
                }
                else if (t[u]!=0){
                    t[u]--;
                    if (t[u]==0) q.push(u);
                }
            }
        }
        ll p1=0;
        for (int i=0;i<n;i++){
            if (vis[i] || R[i]==0) continue;
            ll p2=0;
            for (auto u : g[i]){
                if (t[u]==0) p2=1;
            }
            if (p2==0){
                p1=1;
                vis[i]=1;
            }
        }
        if (p1==0) break;
	}
	ll p1=0;
	for (int i=0;i<n;i++){
        if (vis[i]==0 && R[i]==1) p1=1;
	}
	vector <int32_t> ans;
	for (int i=0;i<n;i++){
        if (p1==0) ans.pb(0);
        else {
            if (t[i]==0) ans.pb(1);
            else ans.pb(0);
        }
	}
	return ans;
}
/*
int32_t main() {
	int n, m;
	assert(2 == scanf("%d %d", &n, &m));

	vector<int32_t> a(n), r(n), u(m), v(m);

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &a[i]));

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &r[i]));

	for(int i = 0; i < m; i++)
		assert(2 == scanf("%d %d", &u[i], &v[i]));

	vector<int32_t> res = who_wins(a, r, u, v);

	for(int i = 0; i < (int)res.size(); i++)
		printf(i ? " %d" : "%d", res[i]);
	printf("\n");

	return 0;
}
*/
/*
2 4
0 1
1 0
0 0
0 1
1 0
1 1
*/

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:23:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for (int i=0;i<U.size();i++){
      |               ~^~~~~~~~~
train.cpp:22:16: warning: unused variable 'm' [-Wunused-variable]
   22 |  ll n=A.size(),m=U.size();
      |                ^
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1100 KB 3rd lines differ - on the 42nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Incorrect 1 ms 436 KB 3rd lines differ - on the 12th token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 75 ms 1632 KB Output is correct
2 Correct 141 ms 1616 KB Output is correct
3 Correct 185 ms 1612 KB Output is correct
4 Correct 10 ms 1612 KB Output is correct
5 Correct 13 ms 1832 KB Output is correct
6 Correct 11 ms 1868 KB Output is correct
7 Correct 10 ms 1840 KB Output is correct
8 Correct 9 ms 1740 KB Output is correct
9 Correct 8 ms 1740 KB Output is correct
10 Correct 9 ms 1740 KB Output is correct
11 Correct 9 ms 1740 KB Output is correct
12 Correct 8 ms 1612 KB Output is correct
13 Correct 9 ms 1868 KB Output is correct
14 Correct 10 ms 1832 KB Output is correct
15 Correct 10 ms 1832 KB Output is correct
16 Correct 10 ms 1868 KB Output is correct
17 Correct 10 ms 1836 KB Output is correct
18 Correct 352 ms 1296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1460 KB 3rd lines differ - on the 696th token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1612 KB Output is correct
2 Correct 11 ms 1860 KB Output is correct
3 Correct 9 ms 1844 KB Output is correct
4 Correct 9 ms 1740 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 5 ms 1068 KB Output is correct
7 Correct 6 ms 1464 KB Output is correct
8 Correct 6 ms 1588 KB Output is correct
9 Correct 6 ms 1484 KB Output is correct
10 Correct 2 ms 844 KB Output is correct
11 Correct 6 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1100 KB 3rd lines differ - on the 42nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -