Submission #1045366

# Submission time Handle Problem Language Result Execution time Memory
1045366 2024-08-05T21:13:35 Z mariaclara Comparing Plants (IOI20_plants) C++17
0 / 100
2 ms 4964 KB
#include "plants.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second

int n;
vector<int> edges[MAXN]; // menor pro maior
vector<bool> vis;

bool dfs(int x, int find) {
	vis[x] = 1;
	if(x == find) return 1;
	for(int viz : edges[x]) {
		if(!vis[viz] and dfs(viz, find)) return 1;
	}
	return 0;
}
void init(int k, vector<int> r) {
	n = sz(r);
	
	for(int i = 0; i < n; i++) r.pb(r[i]);

	for(int t = n; t >= 1; t--) {
		vector<int> to_erase;

		for(int i = 0, last = -k; i < 2*n; i++) {
			if(r[i] != 0) continue;
			if(i < n) { last = i; continue; }
			if(i - last >= k) to_erase.pb(i);
			else if(edges[i%n].empty() or edges[i%n].back() != last) edges[i%n].pb(last%n);
			last = i;
		}

		if(to_erase.empty()) break;

		for(int x : to_erase) {
			bool ok = 1;
			for(int i = x; i > x-k; i--) {
				r[i%n]--;
				r[i%n + n]--;
				if(r[i] == 0) edges[i%n].pb(x%n);
			}
			for(int i = x; i < x+k; i++)
				edges[i%n].pb(x%n);
		}
	}

	// for(int i = 0; i < n; i++)
	// 	for(int x : edges[i])
	// 		cout << i << " -> " << x << "\n";
	return;
}

int compare_plants(int x, int y) {
	vis.clear(); vis.resize(n,0);
	if(dfs(y,x)) return 1;
	vis.clear(); vis.resize(n,0);
	if(dfs(x,y)) return -1;
	return 0;
}

Compilation message

plants.cpp: In function 'void init(int, std::vector<int>)':
plants.cpp:47:9: warning: unused variable 'ok' [-Wunused-variable]
   47 |    bool ok = 1;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Incorrect 1 ms 4956 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Incorrect 1 ms 4956 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Incorrect 1 ms 4956 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Incorrect 2 ms 4964 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Incorrect 1 ms 4956 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4952 KB Output is correct
3 Incorrect 1 ms 4956 KB Output isn't correct
4 Halted 0 ms 0 KB -