Submission #390130

# Submission time Handle Problem Language Result Execution time Memory
390130 2021-04-15T12:07:44 Z mehrdad_sohrabi Toy Train (IOI17_train) C++14
23 / 100
299 ms 1688 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);
                t[i]=0;
            }
        }
        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 && A[i]==0 && R[i]==0 && g[i].size()>1 && (g[i][0]==i || g[i][1]==i)) cout << 1/0;
            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:74:104: warning: division by zero [-Wdiv-by-zero]
   74 |             if (t[i]==0 && A[i]==0 && R[i]==0 && g[i].size()>1 && (g[i][0]==i || g[i][1]==i)) cout << 1/0;
      |                                                                                                       ~^~
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 1108 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 Correct 1 ms 460 KB Output is correct
3 Incorrect 1 ms 460 KB 3rd lines differ - on the 3rd token, expected: '0', found: '1'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 76 ms 1644 KB Output is correct
2 Correct 141 ms 1628 KB Output is correct
3 Correct 193 ms 1600 KB Output is correct
4 Correct 10 ms 1612 KB Output is correct
5 Correct 13 ms 1688 KB Output is correct
6 Correct 10 ms 1632 KB Output is correct
7 Correct 9 ms 1612 KB Output is correct
8 Correct 9 ms 1484 KB Output is correct
9 Correct 8 ms 1484 KB Output is correct
10 Correct 8 ms 1484 KB Output is correct
11 Correct 8 ms 1484 KB Output is correct
12 Correct 8 ms 1484 KB Output is correct
13 Correct 9 ms 1636 KB Output is correct
14 Correct 10 ms 1612 KB Output is correct
15 Correct 9 ms 1612 KB Output is correct
16 Correct 9 ms 1612 KB Output is correct
17 Correct 10 ms 1628 KB Output is correct
18 Correct 299 ms 1164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1356 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 10 ms 1632 KB Output is correct
2 Correct 10 ms 1632 KB Output is correct
3 Correct 9 ms 1668 KB Output is correct
4 Correct 10 ms 1484 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 4 ms 1100 KB Output is correct
7 Correct 5 ms 1228 KB Output is correct
8 Correct 6 ms 1356 KB Output is correct
9 Correct 6 ms 1356 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 6 ms 1204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1108 KB 3rd lines differ - on the 42nd token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -