提出 #5285414


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int main(){
  int n,d;
  cin>>n>>d;
  vector<int> r(n);
  rep(i,n) cin>>r[i];
  sort(all(r));

  long ans = 0;
  rep(i,n-2){
    if(r[i+2] > r[i] + d) continue;
    int j = lower_bound(all(r), r[i] + d + 1) - r.begin();
    long w = j-i-1;
    ans += w*(w-1)/2;
  }

  cout << ans << endl;

  return 0;
}

提出情報

提出日時
問題 C - Make a Team
ユーザ tossy
言語 C++14 (GCC 5.4.1)
得点 300
コード長 1206 Byte
結果 AC
実行時間 51 ms
メモリ 640 KiB

ジャッジ結果

セット名 all sample
得点 / 配点 300 / 300 0 / 0
結果
AC × 28
AC × 3
セット名 テストケース
all sample01, sample02, sample03, test01, test02, test03, test04, test05, test06, test07, test08, test09, test10, test11, test12, test13, test14, test15, test16, test17, test18, test19, test20, test21, test22, test23, test24, test25
sample sample01, sample02, sample03
ケース名 結果 実行時間 メモリ
sample01 AC 1 ms 256 KiB
sample02 AC 1 ms 256 KiB
sample03 AC 1 ms 256 KiB
test01 AC 1 ms 256 KiB
test02 AC 2 ms 256 KiB
test03 AC 2 ms 256 KiB
test04 AC 42 ms 512 KiB
test05 AC 47 ms 640 KiB
test06 AC 35 ms 512 KiB
test07 AC 40 ms 512 KiB
test08 AC 26 ms 384 KiB
test09 AC 47 ms 640 KiB
test10 AC 41 ms 640 KiB
test11 AC 51 ms 640 KiB
test12 AC 47 ms 640 KiB
test13 AC 50 ms 640 KiB
test14 AC 47 ms 640 KiB
test15 AC 49 ms 640 KiB
test16 AC 51 ms 640 KiB
test17 AC 49 ms 640 KiB
test18 AC 48 ms 640 KiB
test19 AC 45 ms 640 KiB
test20 AC 51 ms 640 KiB
test21 AC 50 ms 640 KiB
test22 AC 50 ms 640 KiB
test23 AC 49 ms 640 KiB
test24 AC 49 ms 640 KiB
test25 AC 1 ms 256 KiB