結果

問題 No.33 アメーバがたくさん
ユーザー woodsgreenwoodsgreen
提出日時 2022-01-11 12:33:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 952 bytes
コンパイル時間 1,859 ms
コンパイル使用メモリ 196,272 KB
最終ジャッジ日時 2025-01-27 10:24:00
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
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%d%d",&n,&d,&t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:16:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         scanf("%lld",&x[i]);
      |         ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int D=1e9;
int n,d,t,done[100];
long long x[100],sz,bef,res;
struct R{
    long long st,ed;
} r[100];
bool cmp(const R &a,const R &b){
    if(a.st==b.st) return a.ed<b.ed;
    return a.st<b.st;
}
int main(){
    scanf("%d%d%d",&n,&d,&t);
    for(int i=0;i<n;++i){
        scanf("%lld",&x[i]);
        x[i]+=D;
    }
    for(int k=0;k<n;++k)
        if(!done[k]){
            sz=0;
            for(int i=0;i<n;++i)
                if((x[i]-x[k])%d==0){
                    r[sz].st=x[i]/d;
                    r[sz].ed=x[i]/d+2*t;
                    sz++;
                    done[i]=1;
                }
            sort(r,r+sz,cmp);
            bef=-1;
            for(int i=0;i<sz;++i){
                bef=max(bef,r[i].st);
                res+=r[i].ed-bef+1;
                bef=r[i].ed+1;
            }
        }
    printf("%lld\n",res);
    return 0;
}
0