結果

問題 No.33 アメーバがたくさん
ユーザー face4face4
提出日時 2018-11-03 12:48:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,232 bytes
コンパイル時間 1,107 ms
コンパイル使用メモリ 97,924 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-30 20:47:33
合計ジャッジ時間 1,855 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;

typedef long long ll;

int main(){
    int n;
    ll d, t;
    cin >> n >> d >> t;
    
    // modulo, val
    map<ll, vector<ll>> m;
    map<ll, vector<pair<ll,ll>>> seg;

    ll x[n];
    for(int i = 0; i < n; i++)  cin >> x[i];
    sort(x, x+n);

    for(int i = 0; i < n; i++){
        ll modulo;
        if(x[i] < 0)   modulo = d - (abs(x[i])%d);
        else           modulo = x[i]%d;
        m[modulo].push_back(x[i]);
    }
    
    for(auto p : m){
        for(ll l : p.second){
            seg[p.first].push_back({l-t*d, l+t*d});
        }
    }

    for(auto p : seg){
        auto it = seg[p.first].begin();
        while(it != seg[p.first].end()){
            auto next = it;
            next++;
            
            if(next == seg[p.first].end())  break;

            if((*it).second >= (*next).first){
                (*it).second = (*next).second;
                seg[p.first].erase(next);
            }else{
                it++;
            }

        }
    }

    ll ans = 0;
    for(auto p : seg){
        for(auto q : p.second)  ans += (q.second-q.first)/d + 1;
    }

    cout << ans << endl;
    
    return 0;
}
0