結果
問題 |
No.1233 割り切れない気持ち
|
ユーザー |
|
提出日時 | 2020-10-04 16:52:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 39 ms / 3,153 ms |
コード長 | 649 bytes |
コンパイル時間 | 1,872 ms |
コンパイル使用メモリ | 195,984 KB |
最終ジャッジ日時 | 2025-01-15 02:43:57 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 39 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | int n; scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; int main(){ int n; scanf("%d",&n); vector<int> a(n); rep(i,n) scanf("%d",&a[i]); int amax=*max_element(a.begin(),a.end()); vector<lint> freq(amax+1); rep(i,n) freq[a[i]]++; vector<lint> sum1(amax+1),sum2(amax+1); for(int x=1;x<=amax;x++){ sum1[x]=sum1[x-1]+freq[x]; sum2[x]=sum2[x-1]+x*freq[x]; } lint ans=0; for(int y=1;y<=amax;y++) if(freq[y]>0) { for(int q=0;q*y<=amax;q++){ int l=q*y,r=min((q+1)*y-1,amax); ans+=((sum2[r]-sum2[l])-q*y*(sum1[r]-sum1[l]))*freq[y]; } } printf("%lld\n",ans); return 0; }