제출 #1333937

#제출 시각아이디문제언어결과실행 시간메모리
1333937nguyen도서관 (JOI18_library)C++20
컴파일 에러
0 ms0 KiB
#include <cstdio>
#include <vector>
#include "library.h"
using namespace std;

void Solve(int N)
{
	for(int i = 0; i < N; i++)
	{
		int lo = 0, hi = N-1, except = -1, fin = 0;
		if(adj[i].size() == 2) continue;
		if(adj[i].size() == 1) except = adj[i][0];
		while(lo <= hi)
		{
			int x = (lo+hi)/2;
			vector<int> m1(N, 0);
			int cnt = 0;
			
			for(int j = lo; j <= x; j++) if(j != except) m1[j] = 1, cnt++;
			m1[i] = 0;
			if(i <= x && i >= lo) cnt--;
			
			int mcount = 0;
			if(cnt == 0) mcount = -1;
			else mcount = Query(m1);
			
			m1[i] = 1;
			int mafter = Query(m1);
			
			if(mafter <= mcount) 
			{
				fin = x;
				hi = x-1;
			}
			else lo = x+1;
		}
		adj[i].push_back(fin);
		adj[fin].push_back(i);
	}
	vector<int> res;
	int start = 0;
	for(int i = 0; i < N; i++)
	{
		if(adj[i].size())
		{
			start = i;
			break;
		}
	}
	vector<bool> answered(N,false);
	while(res.size() < N)
	{
		res.push_back(start+1);
		answered[start] = true;
		int prev = start;
		start = adj[start][0];
		if(answered[start]) start = adj[prev][1];
	}
	for(int i = 0; i < res.size(); i++)
	{
		 cout<<res[i]<<" "<<adj[i][0]<<" "<<adj[i][1]<<endl;
	 }
	Answer(res);
}

컴파일 시 표준 에러 (stderr) 메시지

library.cpp: In function 'void Solve(int)':
library.cpp:11:20: error: 'adj' was not declared in this scope
   11 |                 if(adj[i].size() == 2) continue;
      |                    ^~~
library.cpp:12:20: error: 'adj' was not declared in this scope
   12 |                 if(adj[i].size() == 1) except = adj[i][0];
      |                    ^~~
library.cpp:37:17: error: 'adj' was not declared in this scope
   37 |                 adj[i].push_back(fin);
      |                 ^~~
library.cpp:44:20: error: 'adj' was not declared in this scope
   44 |                 if(adj[i].size())
      |                    ^~~
library.cpp:56:25: error: 'adj' was not declared in this scope
   56 |                 start = adj[start][0];
      |                         ^~~
library.cpp:61:18: error: 'cout' was not declared in this scope
   61 |                  cout<<res[i]<<" "<<adj[i][0]<<" "<<adj[i][1]<<endl;
      |                  ^~~~
library.cpp:4:1: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    3 | #include "library.h"
  +++ |+#include <iostream>
    4 | using namespace std;
library.cpp:61:37: error: 'adj' was not declared in this scope
   61 |                  cout<<res[i]<<" "<<adj[i][0]<<" "<<adj[i][1]<<endl;
      |                                     ^~~
library.cpp:61:64: error: 'endl' was not declared in this scope
   61 |                  cout<<res[i]<<" "<<adj[i][0]<<" "<<adj[i][1]<<endl;
      |                                                                ^~~~
library.cpp:4:1: note: 'std::endl' is defined in header '<ostream>'; did you forget to '#include <ostream>'?
    3 | #include "library.h"
  +++ |+#include <ostream>
    4 | using namespace std;