結果

問題 No.33 アメーバがたくさん
ユーザー tottoripapertottoripaper
提出日時 2014-11-19 23:49:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,044 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 45,120 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 17:41:48
合計ジャッジ時間 1,032 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |     scanf("%d %lld %lld", &N, &D, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:16:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |     for(int i=0;i<N;i++){scanf("%lld", &xs[i]);}
      |                          ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <algorithm>

typedef long long ll;
typedef std::pair<ll,ll> P;

int N;
ll D, T;
ll xs[100];
bool used[100];

int main(){
    scanf("%d %lld %lld", &N, &D, &T);
    
    for(int i=0;i<N;i++){scanf("%lld", &xs[i]);}
    std::sort(xs, xs+N);

    ll res = 0ll;
    for(int i=0;i<N;i++){
        if(used[i]){continue;}
        used[i] = true;

        ll xi = xs[i];
        std::vector<P> ps;
        for(int j=i;j<N;j++){
            if((xs[j] - xi) % D == 0){
                int mid = (xs[j]-xi) / D;
                ps.push_back(std::make_pair(mid-T, mid+T));
                used[j] = true;
            }
        }

        int size = ps.size();
        for(int i=0,j=0;i<size;){
            P p = ps[i];
            while(j < size && ps[j].first <= p.second){
                p.second = ps[j].second;
                j += 1;
            }

            res += p.second - p.first + 1;
            i = j;
        }
    }

    printf("%lld\n", res);
}
0