結果

問題 No.33 アメーバがたくさん
ユーザー face4face4
提出日時 2018-11-03 12:48:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,232 bytes
コンパイル時間 2,313 ms
コンパイル使用メモリ 97,268 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-13 02:18:45
合計ジャッジ時間 2,264 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 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