提出 #74281134


ソースコード 拡げる

#include<bits/stdc++.h>
//入力系
#define cinll(...) ll __VA_ARGS__; input(__VA_ARGS__);
#define cinint(...) int __VA_ARGS__; input(__VA_ARGS__);
#define cinstr(...) string __VA_ARGS__; input(__VA_ARGS__);
#define cinchar(...) char __VA_ARGS__; input(__VA_ARGS__);
#define cindouble(...) double __VA_ARGS__; input(__VA_ARGS__);
#define cinvll(a,n) vll a(n); rep(i,n) cin>>a[i];
#define cinvvll(a,n,m) vvll a(n,vll(m)); rep(i,n) rep(j,m) cin>>a[i][j];
#define cinvs(a,n) vs a(n); rep(i,n) cin>>a[i];
#define cinvpll(a,n) vpll a(n); rep(i,n) cin>>a[i].fst>>a[i].snd;
//繰り返し系
#define rep1(n) for(ll i=0;i<n;i++)
#define rep2(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,n) for(ll i=a;i<n;i++)
#define rep4(i,a,n,b) for(ll i=a;i<n;i+=b)
#define overload4(a,b,c,d,e,...) e
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mrep1(n) for(ll i=n;i>=0;i--)
#define mrep2(i,n) for(ll i=n;i>=0;i--)
#define mrep3(i,n,a) for(ll i=n;i>=a;i--)
#define mrep4(i,n,a,b) for(ll i=n;i>=a;i-=b)
#define mrep(...) overload4(__VA_ARGS__,mrep4,mrep3,mrep2,mrep1)(__VA_ARGS__)
//iterator系
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
//vector系
#define pb push_back
//書くのが長いやつ
#define fst first
#define snd second
#define cvvll1(name,a,b) vvll name(a, vll(b))
#define cvvll2(name,a,b,c) vvll name(a, vll(b,c))
#define cvvlloverload2(name,a,b,c,d,...) d
#define make_vvll(...) cvvlloverload2(__VA_ARGS__,cvvll2,cvvll1)(__VA_ARGS__)
using namespace std;
//型系
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using pll = pair<long long,long long>;
using pi = pair<int,int>;
using pd = pair<double,double>;
using sll = set<long long>;
using vsll = vector<sll>;
using vpll = vector<pll>;
using vpi = vector<pi>;
using vpd = vector<pd>;
using vvpll  = vector<vpll>;
#define vmll vector<mll>
#define vvmll vector<vector<mll>>

// const ll mod = 998244353LL;
// const ll mod = 1000000007LL;
const ll mod = 10007;
const ll inf = 1300100100100100100LL;
const double PI=3.1415926535897932384626433832795028841971;

//表示
#define overload1(a,b,NAME,...) NAME
#define coutYesReturn() do {coutYes(); return 0; } while(0)
#define coutYesReturnIf(a) do { if(a){ coutYesReturn(); }} while(0)
#define coutNoReturn() do {coutNo(); return 0;} while(0)
#define coutNoReturnIf(a) do {if(a){ coutNoReturn(); }} while(0)
#define coutReturnIf(a,s) do{if(a){cout<<s<<endl; return 0;}}while(0)
template<typename... T>
void coutll(T... a){ ((cout << a <<" "),...) << endl; }
void coutvll(vll &a){ rep(i,a.size()) cout<<a[i]<<" "; cout<<endl; }
void coutvll(string name, vll &a){ cout<<name<<":"; coutvll(a); }
void coutvlln(vll &a){ rep(i,a.size()) cout<<a[i]<<endl; }
void coutYes(){ cout<<"Yes"<<endl; }
void coutNo(){ cout<<"No"<<endl; }
void coutYesNo(bool a){ cout<<(a?"Yes":"No")<<endl; }
void coutIf(bool a, string s, string t){ cout<<(a?s:t)<<endl; }
//入力
template<class... T>
void input(T&... a){
    (cin >> ... >> a);
}
//複数ソート
template<class... T>
void sorts(vector<T>&... a){
    (sort(all(a)),...);
}
//便利関数
template<typename T> bool chmax(T &a, T b){ if(a < b) {a = b; return true;} return false; }
template<typename T> bool chmin(T &a, T b){ if(a > b) {a = b; return true;} return false; }

//配列表示用
template <typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { 
    rep(i,vec.size()) os << vec[i] << (i==(ll)vec.size()-1?"":" ");
    return os;
}

struct UnionFind {
public:
    vll par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
    vll kosu;
    ll Count; //全体として何個の集合があるか
    
    UnionFind(ll n) : par(n),kosu(n),Count(n) { //最初は全てが根であるとして初期化
        rep(i,n){
            par[i] = i;
            kosu[i] = 1;
        }
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根
        kosu[ry] += kosu[rx];
        Count--;
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
    
    ll size(ll x){
        return kosu[root(x)];
    }
    ll size(){
        return Count;
    }
};

//縦0以上h未満、横0以上w未満の(i,j)の4近傍をとる
vpll kinbo4(ll h,ll w, ll i,ll j){
    vpll ret;
    if(i-1 >= 0) ret.push_back({i-1,j});
    if(j-1 >= 0) ret.push_back({i,j-1});
    if(i+1 < h) ret.push_back({i+1,j});
    if(j+1 < w) ret.push_back({i,j+1});
    return ret;
}

int main(){
    cinll(n, k);
    cinvll(a, n);
    rep(i, n) a[i] %= k;

    sort(all(a));

    ll ans =  a[n-1] - a[0];
    rep(i, n-1){
        chmin(ans, a[i]+k-a[i+1]);
    }
    cout << ans << endl;
    return 0;
}

提出情報

提出日時
問題 D - Minimize Range
ユーザ hoppii
言語 C++23 (GCC 15.2.0)
得点 400
コード長 5537 Byte
結果 AC
実行時間 64 ms
メモリ 4948 KiB

コンパイルエラー

./Main.cpp: In function 'void coutvll(vll&)':
./Main.cpp:14:31: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 | #define rep2(i,n) for(ll i=0;i<n;i++)
      |                               ^
./Main.cpp:17:34: note: in expansion of macro 'rep2'
   17 | #define overload4(a,b,c,d,e,...) e
      |                                  ^
./Main.cpp:18:18: note: in expansion of macro 'overload4'
   18 | #define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
      |                  ^~~~~~~~~
./Main.cpp:77:23: note: in expansion of macro 'rep'
   77 | void coutvll(vll &a){ rep(i,a.size()) cout<<a[i]<<" "; cout<<endl; }
      |                       ^~~
./Main.cpp: In function 'void coutvlln(vll&)':
./Main.cpp:14:31: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 | #define rep2(i,n) for(ll i=0;i<n;i++)
      |                               ^
./Main.cpp:17:34: note: in expansion of macro 'rep2'
   17 | #define overload4(a,b,c,d,e,...) e
      |                                  ^
./Main.cpp:18:18: note: in expansion of macro 'overload4'
   18 | #define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
      |                  ^~~~~~~~~
./Main.cpp:79:24: note: in expansion of macro 'rep'
   79 | void coutvlln(vll &a){ rep(i,a.size()) cout<<a[i]<<endl; }
      |                        ^~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 44
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_01.txt, 01_02.txt, 01_03.txt, 01_04.txt, 01_05.txt, 01_06.txt, 01_07.txt, 01_08.txt, 01_09.txt, 01_10.txt, 01_11.txt, 01_12.txt, 01_13.txt, 01_14.txt, 01_15.txt, 01_16.txt, 01_17.txt, 01_18.txt, 01_19.txt, 01_20.txt, 02_01.txt, 02_02.txt, 02_03.txt, 02_04.txt, 02_05.txt, 02_06.txt, 02_07.txt, 02_08.txt, 02_09.txt, 02_10.txt, 02_11.txt, 02_12.txt, 03_01.txt, 03_02.txt, 03_03.txt, 03_04.txt, 03_05.txt, 03_06.txt, 03_07.txt, 03_08.txt, 03_09.txt, 03_10.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 1 ms 3584 KiB
00_sample_02.txt AC 1 ms 3484 KiB
01_01.txt AC 32 ms 4052 KiB
01_02.txt AC 35 ms 4148 KiB
01_03.txt AC 53 ms 4532 KiB
01_04.txt AC 30 ms 4028 KiB
01_05.txt AC 20 ms 3768 KiB
01_06.txt AC 15 ms 3668 KiB
01_07.txt AC 8 ms 3580 KiB
01_08.txt AC 11 ms 3680 KiB
01_09.txt AC 43 ms 4416 KiB
01_10.txt AC 9 ms 3536 KiB
01_11.txt AC 19 ms 3792 KiB
01_12.txt AC 30 ms 4044 KiB
01_13.txt AC 13 ms 3576 KiB
01_14.txt AC 26 ms 3892 KiB
01_15.txt AC 17 ms 3716 KiB
01_16.txt AC 2 ms 3416 KiB
01_17.txt AC 45 ms 4300 KiB
01_18.txt AC 41 ms 4268 KiB
01_19.txt AC 57 ms 4820 KiB
01_20.txt AC 42 ms 4276 KiB
02_01.txt AC 1 ms 3636 KiB
02_02.txt AC 1 ms 3584 KiB
02_03.txt AC 1 ms 3424 KiB
02_04.txt AC 1 ms 3468 KiB
02_05.txt AC 1 ms 3424 KiB
02_06.txt AC 1 ms 3600 KiB
02_07.txt AC 20 ms 4868 KiB
02_08.txt AC 56 ms 4748 KiB
02_09.txt AC 52 ms 4948 KiB
02_10.txt AC 20 ms 4792 KiB
02_11.txt AC 56 ms 4876 KiB
02_12.txt AC 63 ms 4940 KiB
03_01.txt AC 63 ms 4880 KiB
03_02.txt AC 63 ms 4820 KiB
03_03.txt AC 63 ms 4876 KiB
03_04.txt AC 63 ms 4792 KiB
03_05.txt AC 64 ms 4820 KiB
03_06.txt AC 63 ms 4832 KiB
03_07.txt AC 63 ms 4684 KiB
03_08.txt AC 63 ms 4876 KiB
03_09.txt AC 63 ms 4876 KiB
03_10.txt AC 63 ms 4792 KiB