結果

問題 No.594 壊れた宝物発見機
ユーザー finefine
提出日時 2017-11-10 23:26:32
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 3,151 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 170,184 KB
実行使用メモリ 24,324 KB
平均クエリ数 176.25
最終ジャッジ日時 2023-09-23 14:54:44
合計ジャッジ時間 4,713 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
23,604 KB
testcase_01 AC 99 ms
23,976 KB
testcase_02 AC 103 ms
24,048 KB
testcase_03 AC 101 ms
23,556 KB
testcase_04 AC 100 ms
24,048 KB
testcase_05 AC 100 ms
23,340 KB
testcase_06 AC 105 ms
23,976 KB
testcase_07 AC 101 ms
24,324 KB
testcase_08 AC 101 ms
23,376 KB
testcase_09 AC 96 ms
24,072 KB
testcase_10 AC 101 ms
24,012 KB
testcase_11 AC 96 ms
23,652 KB
testcase_12 AC 98 ms
24,036 KB
testcase_13 AC 97 ms
23,568 KB
testcase_14 AC 107 ms
23,364 KB
testcase_15 AC 99 ms
23,688 KB
testcase_16 AC 102 ms
23,364 KB
testcase_17 AC 99 ms
23,364 KB
testcase_18 AC 101 ms
23,640 KB
testcase_19 AC 100 ms
23,796 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:132:11: 警告: ‘ap.Point::z’ may be used uninitialized [-Wmaybe-uninitialized]
  132 |     answer(ap.x, ap.y, ap.z);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:63:11: 備考: ‘ap.Point::z’ はここで定義されています
   63 |     Point ap;
      |           ^~
main.cpp:132:11: 警告: ‘ap.Point::y’ may be used uninitialized [-Wmaybe-uninitialized]
  132 |     answer(ap.x, ap.y, ap.z);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:63:11: 備考: ‘ap.Point::y’ はここで定義されています
   63 |     Point ap;
      |           ^~
main.cpp:132:11: 警告: ‘ap.Point::x’ may be used uninitialized [-Wmaybe-uninitialized]
  132 |     answer(ap.x, ap.y, ap.z);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:63:11: 備考: ‘ap.Point::x’ はここで定義されています
   63 |     Point ap;
      |           ^~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int ax = -25, ay = 25, az = 35;

// 質問クエリ
int ask(int x, int y, int z) {
	int d;
	cout << "?" << " " << x << " " << y << " " << z << endl;
    cin >> d;
	return d;//(ax - x) * (ax - x) + (ay - y) * (ay - y) + (az - z) * (az - z);
}

// 回答クエリ
void answer(int x, int y, int z) {
	cout << "!" << " " << x << " " << y << " " << z << endl;
}

struct Point {
    int x;
    int y;
    int z;
};

bool judge(vector<Point>& v) {
    return v[1].x - v[0].x > 1 || v[2].y - v[0].y > 1 || v[4].z - v[0].z > 0;
}

int mid(int x, int y) {
    int sum = x + y;
    return sum / 2;
    /*
    if (sum < 0) return (sum - 1) / 2;
    else return (sum + 1) / 2;
    */
}

int mid2(int x, int y) {
    int sum = x + y;
    if (sum < 0) return (sum - 1) / 2;
    else return (sum + 1) / 2;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<Point> v;
    for (int i = 0; i < 8; i++) {
        int x, y, z;
        if (i & 1) x = 150;
        else x = -150;
        if (i & 2) y = 150;
        else y = -150;
        if (i & 4) z = 150;
        else z = -150;
        v.push_back((Point){x, y, z});
    }
    int idx = -1, vmax = 1145141919;
    int cnt = 0;
    Point ap;
    vector<int> ans(8);
    while (judge(v) && cnt < 93) {     
        for (int i = 0; i < 8; i++) {
            if (idx == i) continue;
            ans[i] = ask(v[i].x, v[i].y, v[i].z);
            cnt++;
        }
        int ti = 0;
        for (int i = 1; i < 8; i++) {
            if (ans[i] < ans[ti]) {
                ti = i;
            }
        }
        idx = ti;
        if (ans[idx] < vmax) {
            vmax = ans[idx];
            ap.x = v[idx].x;
            ap.y = v[idx].y;
            ap.z = v[idx].z;
        }
        Point p = v[idx];
        for (int i = 0; i < 8; i++) {
            if (idx == i) continue;
            v[i].x = mid(v[i].x, v[idx].x);
            v[i].y = mid(v[i].y, v[idx].y);
            v[i].z = mid(v[i].z, v[idx].z);
        }
    }
    v.clear();
    for (int i = 0; i < 8; i++) {
        int x, y, z;
        if (i & 1) x = 150;
        else x = -150;
        if (i & 2) y = 150;
        else y = -150;
        if (i & 4) z = 150;
        else z = -150;
        v.push_back((Point){x, y, z});
    }
    cnt = 0;
    idx = -1;
    while (judge(v) && cnt < 93) {     
        for (int i = 0; i < 8; i++) {
            if (idx == i) continue;
            ans[i] = ask(v[i].x, v[i].y, v[i].z);
            cnt++;
        }
        int ti = 0;
        for (int i = 1; i < 8; i++) {
            if (ans[i] < ans[ti]) {
                ti = i;
            }
        }
        idx = ti;
        if (ans[idx] < vmax) {
            vmax = ans[idx];
            ap.x = v[idx].x;
            ap.y = v[idx].y;
            ap.z = v[idx].z;
        }
        Point p = v[idx];
        for (int i = 0; i < 8; i++) {
            if (idx == i) continue;
            v[i].x = mid2(v[i].x, v[idx].x);
            v[i].y = mid2(v[i].y, v[idx].y);
            v[i].z = mid2(v[i].z, v[idx].z);
        }
    }
    answer(ap.x, ap.y, ap.z);
    return 0;
}
0