結果

問題 No.5017 Tool-assisted Shooting
ユーザー かえで
提出日時 2023-07-16 15:49:29
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 3,181 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 145,456 KB
実行使用メモリ 24,504 KB
スコア 36,417
平均クエリ数 178.23
最終ジャッジ日時 2023-07-16 15:49:44
合計ジャッジ時間 14,231 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 59 RE * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//fixed,setprecision
//#include <limits.n>//INT_MAX
//#include <math.n>//M_PI
#include <random>
#include <regex> // 正規表現
#include <time.h>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

constexpr int width = 25;        // フィールドの幅
constexpr int height = 60;       // フィールドの高さ
constexpr int max_turn = 1000;   // ゲームの最大ターン数
const char choice[3] = {'L', 'R', 'S'};
int sx = 12;
struct Data {
    int h;
    int p;
    int x;
    int y;

    Data(int h, int p, int x, int y) : h(h), p(p), x(x), y(y) {}
};

bool compareByH(const Data& a, const Data& b) {
    return a.h < b.h;
}

bool compareByX(const Data& a, const Data& b) {
    return abs(a.x - sx) < abs(b.x - sx);
}

int main() {
    vector<Data> data;
    for (int turn = 1; turn <= max_turn; turn++) {
        // 入力の受け取り
        int n;
        cin >> n;
        if (n == -1)
            return 0;

        for (int i = 0; i < n; i++) {
            int h1, p1, x1;
            cin >> h1 >> p1 >> x1;
            data.emplace_back(h1, p1, x1, 59);
        }

        if (!data.empty()) {
            sort(data.begin(), data.end(), compareByH);
            sort(data.begin(), data.end(), compareByX);
        }

        int r = 0;
        if (sx > data[0].x&&sx>=1) {
            r = 0;
            sx--;
        } else if (sx < data[0].x&&sx<23) {
            r = 1;
            sx++;
        } else {
            r = 2;
            if (data[0].y <2) {
                if (sx >= 1) {
                    sx--;
                    r = 0;
                } else {
                    sx++;
                    r = 1;
                }
            }
        }

        char c = choice[r];
        cout << c << endl;
        cout << "#" << c << " sx:" << sx << endl;
        int ichi = 100;
        if (!data.empty()) {
            for (auto& z : data) {
                z.y -= 1;
                if (z.x == sx) {
                    ichi = min(ichi, z.y);
                }
            }
        }
        if (ichi != -1) {
            for (auto it = data.begin(); it != data.end(); ++it) {
                if (ichi == it->y && it->x == sx) {
                    if (it->h != 0) {
                        it->h -= 1;
                    } else {
                        data.erase(it);
                    }
                    break;
                }
            }
        }
    }

    return 0;
}
0