結果

問題 No.3257 +|+
ユーザー 沙耶花
提出日時 2025-09-05 22:24:07
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,092 bytes
コンパイル時間 6,045 ms
コンパイル使用メモリ 334,184 KB
実行使用メモリ 13,988 KB
最終ジャッジ日時 2025-09-05 22:24:55
合計ジャッジ時間 29,654 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000005
#define Inf64 1000000000000000001LL


int main(){
	
	int n;
	cin>>n;
	vector<long long> a(n);
	rep(i,n)cin>>a[i];
	
	long long ans = 0;
	for(long long i=2;i<=1010;i++){
		for(long long j=1;j<i;j++){
			int ii = j-1,jj = (i-j)-1;
			if(jj>=n)continue;
			if(ii>=jj)break;
			if((a[ii]+a[jj])%i==0&&(a[ii]+a[jj])/i>500){
				ans++;
			}
		}
	}
	for(long long i=1;i<=500;i++){
		vector<long long> t(n);
		rep(j,n){
			t[j] = a[j] - (j+1) * i;
		}
		sort(t.begin(),t.end());
		long long pre = 0;
		rep(j,n){
			if(t[j] < 0)continue;
			if(j>0 && t[j-1]==t[j]){
				if(t[j]==0){
					pre++;
					ans += pre;
				}
				else{
					ans += pre;
				}
				continue;
			}
			pre = 0;
			int d = distance(t.begin(),lower_bound(t.begin(),t.end(),-t[j]));
			while(d<j){
				if(t[d]==-t[j]){
					ans++;
					pre++;
					d++;
				}
				else{
					break;
				}
			}
		}
	}
	cout<<ans<<endl;
}
0