Submission #681957

# Submission time Handle Problem Language Result Execution time Memory
681957 2023-01-14T23:48:24 Z Mher777 Easter Eggs (info1cup17_eastereggs) C++14
16 / 100
2 ms 464 KB
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <fstream>
#include "grader.h"
using namespace std;

const int N = 600;

vector<int> g[N];
vector<int> a;
vector<bool> used(N);

void dfs(int u) {
	used[u] = 1;
	for (int i = 0; i < g[u].size(); i++) {
		if (!used[g[u][i]]) {
			used[g[u][i]] = true;
			a.push_back(g[u][i]);
			dfs(g[u][i]);
		}
	}
}

int findEgg (int n, vector<pair<int,int>> b) {
	for (int i = 1; i <= n; i++) used[i] = false;
	a.clear();
	for (int i = 0; i < b.size(); i++) {
		if (b[i].second < b[i].first) swap(b[i].first, b[i].second);
		g[b[i].first].clear();
	}
	for (int i = 0; i < b.size(); i++) {
		g[b[i].first].push_back(b[i].second);
	}
	for (int i = 1; i <= n; i++) {
		if (!used[i]) {
			vector<int> v1;
			a.clear();
			a.push_back(i);
			dfs(i);
			if (query(a) == 0) {
				continue;
			}
			if (a.size() == 1) {
				return a[0];
			}
			int l = 0, r = a.size() - 1, mid = (l + r) / 2;
			while (l <= r) {
				mid = (l + r) / 2;
				if (r == a.size() - 1 && l == a.size() - 1) {
					return a[r];
				}
				for (int i = 0; i <= mid; i++) {
					v1.push_back(a[i]);
				}
				if (query(v1) == 1) {
					a = v1;
					if (r - l + 1 == 1) {
						return v1[l];
					}
					r = mid;
				}
				else {
					l = mid + 1;
				}
				v1.clear();
			}
		}
	}
}

Compilation message

eastereggs.cpp: In function 'void dfs(int)':
eastereggs.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for (int i = 0; i < g[u].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for (int i = 0; i < b.size(); i++) {
      |                  ~~^~~~~~~~~~
eastereggs.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for (int i = 0; i < b.size(); i++) {
      |                  ~~^~~~~~~~~~
eastereggs.cpp:68:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     if (r == a.size() - 1 && l == a.size() - 1) {
      |         ~~^~~~~~~~~~~~~~~
eastereggs.cpp:68:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     if (r == a.size() - 1 && l == a.size() - 1) {
      |                              ~~^~~~~~~~~~~~~~~
eastereggs.cpp:88:1: warning: control reaches end of non-void function [-Wreturn-type]
   88 | }
      | ^
# Verdict Execution time Memory Grader output
1 Partially correct 2 ms 208 KB Number of queries: 8
2 Partially correct 2 ms 292 KB Number of queries: 7
3 Partially correct 1 ms 208 KB Number of queries: 9
4 Partially correct 1 ms 208 KB Number of queries: 14
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -