답안 #230942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
230942 2020-05-12T03:51:59 Z jiahng Go, Gopher! (GCJ18Q_gogopher) C++14
30 / 30
102 ms 1280 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

int TC;
int A,W,H;
bool done[1000][1000];

int dx[9] = {0,0,0,-1,1,-1,1,-1,1};
int dy[9] = {0,-1,1,-1,1,0,0,1,-1};

int main(){
	fast;
	
	cin>>TC;
	
	while (TC--){
		cin>>A;
		
		
		if (A == 20){
			W = 4;
			H = 5;
		}else{
			W = 40;
			H = 5;
		}
		
		pi tl = pi(500,500);
		pi br = pi(500 + W - 1,500 + H - 1);

		mem(done,0);
		bool finish = 0;
		FOR(i,tl.f,br.f){
			FOR(j,tl.s,br.s){
				
				while (!done[i][j]){
					pi qry;
					int curmn = 10;
					
					FOR(k,0,8){
						pi cur = pi(i+dx[k],j+dy[k]);
						
						if (cur.f <= tl.f || cur.f >= br.f || cur.s <= tl.s || cur.s >= br.s) continue;
						
						int num = 0;
						FOR(l,0,8){
							if (done[cur.f + dx[l]][cur.s + dy[l]]) num++;
						}
						
						if (num < curmn){
							curmn = num;
							qry = cur;
						}
					}
					cout<<qry.f<<' '<<qry.s<<'\n';
					cout.flush();
					
					int a,b;
					cin>>a>>b;
					if (a == -1 && b == -1) finish = 1;
					if (a == 0 && b == 0) finish = 1;
					if (finish) break;
					done[a][b] = 1;
				}
				if (finish) break;
			}
			if (finish) break;
		}
		
	}
}

# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 1280 KB Output is correct