結果

問題 No.33 アメーバがたくさん
ユーザー ktgktg
提出日時 2016-10-08 21:24:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,345 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 86,696 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 20:19:06
合計ジャッジ時間 1,261 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//#include <bits/stdc++.h>
#include <assert.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <iterator>
#include <unistd.h>

using namespace std;

typedef signed long long ll;

#define pp(...) (void)printf(__VA_ARGS__)
#define For(x,to) for(x=0;x<(to);x++)
#define ForAuto(x,arr) for(auto& x:arr)
#define ForBeginEnd(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define All(a) (a.begin()),(a.end())
#define Zeros(a) memset(a,0,sizeof(a))
#define Minus(a) memset(a,0xff,sizeof(a))

#define PI 3.14159265
#define EPS (1e-10)
#define EPS_eq(a,b) (abs((a)-(b)) < EPS)

#pragma GCC diagnostic ignored "-Wconversion"

//#define int long long
#define INF 1000*1000

int dxy[] = {0, 1, 0, -1, 0};

typedef pair<int, int> P;

void pp_int(int x){ printf("%d\n", x); };

int i,j,k;

ll M = 100000009;

//ios::sync_with_stdio(false);

//-------------------------------------------------

signed main() {
    ll N,D,T;
    cin>>N>>D>>T;
    vector<ll> X(N);

    for(int i=0;i<N;i++)
        cin>>X[i];
    sort(X.begin(), X.end());

    if (X[0] < 0) {
        ll x0 = -X[0];
        for(int i=0;i<N;i++)
            X[i] += x0;
    }

    ll ret = 0;
    ret += N;
//    cout<<"init:"<<ret<<endl;
    for(int i=0;i<N;i++){
        // 左をチェック
        bool found = false;
        for(int j=i-1;j>=0;j--) {
            ll diff = X[i] - X[j];
            if (diff % D == 0) {
                ll mx_count = diff / D - 1;
                if (mx_count > T){
                    ret += min(T, mx_count - T);
                }
                found = true;
                break;
            }
        }
        if (!found) {
            ret += T;
        }
//        cout<<"left:"<<i<<":"<<ret<<endl;
        found = false;
        // 右をチェック
        for(int j=i + 1;j < N;j++) {
            ll diff = X[j] - X[i];
            if (diff % D == 0) {
                ll mx_count = diff / D - 1;
                ret += min(T, mx_count);
                found = true;
                break;
            }
        }
        if (!found) {
            ret += T;
        }
//        cout<<"right:"<<i<<":"<<ret<<endl;
    }
    cout<<ret<<endl;
    return 0;
}
0