結果

問題 No.511 落ちゲー 〜手作業のぬくもり〜
ユーザー mamekinmamekin
提出日時 2017-04-29 00:12:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 4,000 ms
コード長 2,575 bytes
コンパイル時間 1,058 ms
コンパイル使用メモリ 112,300 KB
実行使用メモリ 6,408 KB
最終ジャッジ日時 2023-08-16 03:07:32
合計ジャッジ時間 3,459 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 111 ms
6,136 KB
testcase_30 AC 91 ms
5,604 KB
testcase_31 AC 86 ms
5,368 KB
testcase_32 AC 102 ms
6,272 KB
testcase_33 AC 106 ms
6,328 KB
testcase_34 AC 103 ms
6,408 KB
testcase_35 AC 110 ms
6,076 KB
testcase_36 AC 110 ms
6,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

class BinaryIndexedTree
{
private:
    int n;
    vector<long long> data;
public:
    BinaryIndexedTree(int n){ // コンストラクタ
        this->n = n;
        data.assign(n+1, 0);
    }
    void add(int k, long long x){ // k番目の要素にxを加算する
        ++ k;
        while(k <= n){
            data[k] += x;
            k += k & -k;
        }
    }
    long long sum(int k){ // 区間[0,k]の総和を返す
        ++ k;
        long long ret = 0;
        while(k > 0){
            ret += data[k];
            k -= k & -k;
        }
        return ret;
    }
    long long sum(int a, int b){ // 区間[a,b]の総和を返す
        return sum(b) - sum(a-1);
    }
    int upper_bound(long long x){ // 総和が初めてxを超える位置を返す(ただし、各位置の数値が非負数であることを前提とする)
        int b = 1;
        while(b < n)
            b *= 2;
        int a = 0;
        while(b > 0){
            if(a+b <= n && x >= data[a+b]){
                x -= data[a+b];
                a += b;
            }
            b /= 2;
        }
        return (a < n)? a : -1;
    }
    int lower_bound(long long x){ // 総和が初めてx以上になる位置を返す(ただし、各位置の数値が非負数であることを前提とする)
        return upper_bound(x-1);
    }
};

int main()
{
    int n, w;
    long long h;
    cin >> n >> w >> h;

    vector<tuple<int, int, int> > v(2*n);
    for(int i=0; i<n; ++i){
        int a, b, x;
        cin >> a >> b >> x;
        v[2*i]   = make_tuple(x-1, i, b);
        v[2*i+1] = make_tuple(x-1+a, i, -b);
    }
    sort(v.begin(), v.end());

    BinaryIndexedTree bit(n);
    int k = 0;
    int cnt = 0;
    for(int x=0; x<w; ++x){
        while(k < 2 * n && get<0>(v[k]) == x){
            bit.add(get<1>(v[k]), get<2>(v[k]));
            ++ k;
        }
        int i = bit.lower_bound(h);
        if(i % 2 == 0)
            ++ cnt; 
    }

    if(cnt > w - cnt)
        cout << 'A' << endl;
    else if(cnt == w - cnt)
        cout << "DRAW" << endl;
    else
        cout << 'B' << endl;

    return 0;
}
0