結果

問題 No.33 アメーバがたくさん
ユーザー ayame_pyayame_py
提出日時 2016-01-09 01:55:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 945 bytes
コンパイル時間 1,553 ms
コンパイル使用メモリ 173,972 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 17:55:42
合計ジャッジ時間 2,049 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i < (ll)(m); i++)
#define INF 1000000007

typedef long long ll;
typedef pair<ll,ll> p;

map<ll, vector<p> > l;
ll N, D, T;

int main(){
    cin >> N >> D >> T;
    REP(i,N){
        ll x;
        cin >> x;
        ll t = x;
        while(t<0) t+=D;
        l[t%D].push_back(p(x-D*T,x+D*T));
    }
    ll ans=0;
    for(auto x: l){
        // 範囲が後ろにある順にsort
        vector<p> &e  = x.second;
        sort(e.begin(),e.end());
        size_t s = e.size();
        // 範囲被りを除去
        REP(i,s){
            if(e[i].second>=e[i].first) ans+=(e[i].second-e[i].first)/D+1;
            FOR(j,i+1,s){
                if(e[i].second >= e[j].first){
                    e[j].first=e[i].second+D;
                }
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}
0