結果

問題 No.3257 +|+
ユーザー 👑 hos.lyric
提出日時 2025-09-05 22:06:54
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 649 ms / 3,000 ms
コード長 2,384 bytes
コンパイル時間 1,112 ms
コンパイル使用メモリ 116,672 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-05 22:07:11
合計ジャッジ時間 15,133 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:48:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |     for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
      |                                  ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


// K N log(N) ~ (N/K)^2
constexpr int K = 20;

int N;
vector<int> A;

int main() {
  for (; ~scanf("%d", &N); ) {
    A.assign(N + 1, 0);
    for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
    
    const int maxA = *max_element(A.begin(), A.end());
    
    Int ans = 0;
    for (int k = 1; k <= K; ++k) {
      vector<Int> bs(N);
      for (int i = 1; i <= N; ++i) bs[i - 1] = A[i] - (Int)k * i;
      sort(bs.begin(), bs.end());
      Int here = 0;
      for (int l = 0, r = 0, j = N; --j >= 0; ) {
        for (; l < N && bs[l] + bs[j] <  0; ++l) {}
        for (; r < N && bs[r] + bs[j] <= 0; ++r) {}
        here += ((r - l) - (l <= j && j < r));
      }
//if(here)cerr<<"k = "<<k<<": bs = "<<bs<<", here = "<<here<<endl;
      here /= 2;
      ans += here;
    }
    const int lim = (maxA + maxA) / (K + 1);
    for (int i = 1; i <= N && i <= lim; ++i) for (int j = i + 1; j <= N && i + j <= lim; ++j) {
      const int q = (A[i] + A[j]) / (i + j);
      const int r = (A[i] + A[j]) % (i + j);
      if (q > K && r == 0) {
//cerr<<i<<" "<<j<<endl;
        ++ans;
      }
    }
    
    printf("%lld\n", ans);
  }
  return 0;
}
0