답안 #678895

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
678895 2023-01-06T21:42:57 Z Hacv16 Aliens (IOI07_aliens) C++17
40 / 100
3 ms 316 KB
#include<bits/stdc++.h>
using namespace std;
 
int n, x, y, m, numblock;
map<pair<int, int>, bool> mt;
 
bool check(int x){ return x > 0 && x <= n ;}

bool query(int x, int y){
    if(mt.find({x, y}) != mt.end()) return mt[{x, y}];
    cout << "examine " << x << ' ' << y << '\n'; cout.flush();
    string ans; cin >> ans; return mt[{x, y}] = (ans == "true");
}

pair<int, int> findCenter(int x, int y, int m){
    int l = 0, r = 2 * n / m, curx = x, cury = y, jump = 0;
 
    //Diagonal jump
    while(l <= r){
        int mid = (l + r) >> 1;
        int nx = curx + m * mid, ny = cury + m * mid;
        if(!check(nx) || !check(ny)){ r = mid - 1; continue; }
        if(query(nx, ny)) l = mid + 1, jump = mid;
        else r = mid - 1;
    }   
 
    curx += jump * m;
    cury += jump * m;
 
    l = 0, r = ((n + m - 1) / m), jump = 0;
 
    //Upwards jump
    while(l <= r){
        int mid = (l + r) >> 1;
        int ny = cury + m * (2 * mid);
        if(!check(ny)) { r = mid - 1; continue; }
        if(query(curx, ny)) l = mid + 1, jump = 2 * mid;
        else r = mid - 1;
    }
 
    cury += jump * m;
 
    //Left jump
    l = 0, r = ((n + m - 1)/ m), jump = 0;
 
    while(l <= r){
        int mid = (l + r) >> 1;
        int nx = curx - m * (2 * mid);
        if(!check(nx)){ r = mid - 1; continue; }
        if(query(nx, cury)) l = mid + 1, jump = 2 * mid;
        else r = mid - 1;
    }
 
    curx -= jump * m;
    
    //move to center of current block
    curx += (m - 1) / 2;
    cury -= (m - 1) / 2;
    
    //move to center block
    l = 0, r = ((n + m - 1) / m), jump = 0;
 
    while(l <= r){
        int mid = (l + r) >> 1;
        int nx = curx + m * (2 * mid);
        if(!check(nx)){ r = mid - 1; continue; }
        if(query(nx, cury)) l = mid + 1, jump = 2 * mid;
        else r = mid - 1;
    }
 
    numblock = jump + 1;
 
    curx += ((numblock - 1) / 2) * m;
    cury -= ((numblock - 1) / 2) * m;
    
    return {curx, cury};
}
 
int main(){
    cin >> n >> x >> y;
 
    int up = y, down = y;
 
    while(check(up + 1) && query(x, up + 1)) up++;
    while(check(down - 1) && query(x, down - 1)) down--;
    while(check(x - 1) && query(x - 1, up)) x--;
    
    m = up - down + 1;

    pair<int, int> resp = findCenter(x, up, m);

    cout << "solution " << resp.first << ' ' << resp.second << '\n';

    exit(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 208 KB Output is correct
2 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 3 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Runtime error 3 ms 316 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Runtime error 3 ms 208 KB Execution killed with signal 13
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 208 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -