Submission #800412

# Submission time Handle Problem Language Result Execution time Memory
800412 2023-08-01T14:24:22 Z Antekb Tropical Garden (IOI11_garden) C++17
49 / 100
77 ms 22716 KB
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>;
using namespace std;
#define st first
#define nd second
#define pb push_back
using pii = pair<int, int>;
using vi = vector<int>;

void count_routes(int n, int m, int p, int edg[][2], int q, int QQ[])
{
	vector<pii> E[n][2];
	int naj[n][2], co[n][2], dist[n][2], typ[n][2];
	for(int i=0; i<n; i++){
		naj[i][0]=naj[i][1]=1e9+5;
	}
	for(int i=m-1; i>=0; i--){
		naj[edg[i][0]][0]=i;
		co[edg[i][0]][0]=edg[i][1];
		naj[edg[i][1]][0]=i;
		co[edg[i][1]][0]=edg[i][0];
	}
	for(int i=m-1; i>=0; i--){
		if(naj[edg[i][0]][0]!=i){
			naj[edg[i][0]][1]=i;
			co[edg[i][0]][1]=edg[i][1];
		}
		if(naj[edg[i][1]][0]!=i){
			naj[edg[i][1]][1]=i;
			co[edg[i][1]][1]=edg[i][0];
		}
	}
	for(int i=0; i<n; i++){
		dist[i][0]=dist[i][1]=1e9+5;
		if(naj[i][1]==1e9+5){
			naj[i][1]=naj[i][0];
			co[i][1]=co[i][0];
		}
		//cerr<<i<<" "<<naj[i][0]<<" "<<co[i][0]<<" "<<naj[i][1]<<" "<<co[i][1]<<"\n";
		E[co[i][0]][(naj[i][0]==naj[co[i][0]][0])].pb({i, 0});
		E[co[i][1]][(naj[i][1]==naj[co[i][1]][0])].pb({i, 1});
	}
	vector<pii> V;
	for(int i=0; i<n; i++){
		if(co[i][0]==p){
			V.pb({i, 0});
			dist[i][0]=1;
			typ[i][0]=(naj[i][0]==naj[p][0]);
		}
		if(co[i][1]==p){
			V.pb({i, 1});
			dist[i][1]=1;
			typ[i][1]=(naj[i][1]==naj[p][0]);
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<2; j++){
			//cerr<<i<<" "<<j<<": ";
			for(pii e:E[i][j]){
				//cerr<<"{"<<e.st<<", "<<e.nd<<"} ";
			}
			//cerr<<"\n";
		}
	}
	for(int i=0; i<V.size(); i++){
		//cerr<<V[i].st<<" "<<V[i].nd<<"\n";
		for(pii e:E[V[i].st][V[i].nd]){
			if(dist[e.st][e.nd]!=1e9+5)continue;
			V.pb(e);
			typ[e.st][e.nd]=typ[V[i].st][V[i].nd];
			dist[e.st][e.nd]=dist[V[i].st][V[i].nd]+1;
		}
	}
	vector<vector<int> > cykle;
	vector<pair<int, int> > eve;
	vector<int> eve2;
	for(int i=0; i<n; i++){
		for(int j=0; j<1; j++){
			if(dist[i][j]!=1e9+5){
				//cerr<<i<<" "<<j<<" "<<dist[i][j]<<" "<<typ[i][j]<<": ";
				if(dist[p][typ[i][j]]==1e9+5){
					eve2.pb(dist[i][j]);
					//cerr<<dist[i][j]<<"\n";
				}
				else{
					if(typ[p][typ[i][j]]==typ[i][j]){
						eve.pb({dist[i][j], dist[p][typ[i][j]]});
						//cerr<<"{"<<dist[i][j]<<", "<<dist[p][typ[i][j]]<<"}\n";
					}
					else{
						if(dist[p][typ[i][j]^1]==1e9+5){
							eve2.pb(dist[i][j]);
							eve2.pb(dist[i][j]+dist[p][typ[i][j]]);
							//cerr<<dist[i][j]<<" "<<dist[i][j]+dist[p][typ[i][j]]<<"\n";
						}
						else{
							eve.pb({dist[i][j], dist[p][0]+dist[p][1]});
							eve.pb({dist[i][j]+dist[p][typ[i][j]], dist[p][0]+dist[p][1]});
							//cerr<<"{"<<dist[i][j]<<", "<<dist[p][typ[i][j]]<<"}";
							//cerr<<"{"<<dist[i][j]+dist[p][typ[i][j]]<<", "<<dist[p][0]+dist[p][1]<<"}\n";
						}
					}
				}
			}
		}
	}
	sort(eve.begin(), eve.end());
	sort(eve2.begin(), eve2.end());
	reverse(eve.begin(), eve.end());
	reverse(eve2.begin(), eve2.end());
	vector<pii> Q(q);
	vector<int> ans(q);
	for(int i=0; i<q; i++){
		Q[i].st=QQ[i];
		Q[i].nd=i;
	}
	sort(Q.begin(), Q.end());
	for(pii ii:Q){
		int i=ii.st, qq=ii.nd;
		while(eve2.size() && eve2.back()<i)eve2.pop_back();
		while(eve2.size() && eve2.back()==i)eve2.pop_back(), ans[qq]++;
		while(eve.size() && eve.back().st<=i){
			if(cykle.size()>0 && cykle[0].size()==eve.back().nd){
				cykle[0][eve.back().st%eve.back().nd]++;
			}
			else if(cykle.size()>1 && cykle[1].size()==eve.back().nd){
				cykle[1][eve.back().st%eve.back().nd]++;
			}
			else{
				cykle.pb(vi(eve.back().nd));
				cykle.back()[eve.back().st%eve.back().nd]++;
			}
			eve.pop_back();
		}
		if(cykle.size()>0)ans[qq]+=cykle[0][i%cykle[0].size()];
		if(cykle.size()>1)ans[qq]+=cykle[1][i%cykle[1].size()];
	}
	for(int i=0; i<q; i++){
		answer(ans[i]);
	}
}


Compilation message

garden.cpp:3:24: warning: extra tokens at end of #include directive
    3 | #include<bits/stdc++.h>;
      |                        ^
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:60:12: warning: variable 'e' set but not used [-Wunused-but-set-variable]
   60 |    for(pii e:E[i][j]){
      |            ^
garden.cpp:66:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  for(int i=0; i<V.size(); i++){
      |               ~^~~~~~~~~
garden.cpp:124:40: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  124 |    if(cykle.size()>0 && cykle[0].size()==eve.back().nd){
      |                                        ^
garden.cpp:127:45: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  127 |    else if(cykle.size()>1 && cykle[1].size()==eve.back().nd){
      |                                             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 7 ms 3412 KB Output is correct
12 Correct 14 ms 5204 KB Output is correct
13 Correct 36 ms 17340 KB Output is correct
14 Correct 55 ms 17992 KB Output is correct
15 Correct 77 ms 22716 KB Output is correct
16 Correct 60 ms 15396 KB Output is correct
17 Incorrect 54 ms 13448 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 7 ms 3412 KB Output is correct
12 Correct 14 ms 5204 KB Output is correct
13 Correct 36 ms 17340 KB Output is correct
14 Correct 55 ms 17992 KB Output is correct
15 Correct 77 ms 22716 KB Output is correct
16 Correct 60 ms 15396 KB Output is correct
17 Incorrect 54 ms 13448 KB Output isn't correct
18 Halted 0 ms 0 KB -