답안 #681942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681942 2023-01-14T23:13:33 Z Mher777 Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
2 ms 592 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 = 0; i < b.size(); i++) {
		if (b[i].second < b[i].first) swap(b[i].first, b[i].second);
		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) == -1) continue;
			int l = 0, r = a.size() - 1, mid = (l + r) / 2;
			while (l <= r) {
				mid = (l + r) / 2;
				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;
					r = (l + a.size() - 1) / 2;
				}
				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:44: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]
   44 |  for (int i = 0; i < b.size(); i++) {
      |                  ~~^~~~~~~~~~
eastereggs.cpp:76:1: warning: control reaches end of non-void function [-Wreturn-type]
   76 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 456 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -