提出 #50119257
ソースコード 拡げる
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long n,sig=0;
cin >> n;
vector<long long> x(n);
for(auto &nx : x){
cin >> nx;
sig+=nx;
}
if(sig!=0){cout << "-1\n";return 0;}
// v[i] ... add (1 -2 1) to (i i+1 i+2)
vector<long long> v(n,0);
long long del=0,cur=0;
for(long long i=1;i<n;i++){
v[i]=cur;
del+=x[i];
cur+=del;
}
// v[n-1] + nC = x[0]
long long p=x[0]-v[n-1];
if(p%n!=0){cout << "-1\n";return 0;}
p/=n;
for(long long i=1;i<n;i++){v[i]+=i*p;}
long long h=8e18,res=0;
for(auto &nx : v){h=min(h,nx);}
for(auto &nx : v){
nx-=h;
res+=nx;
}
cout << res << "\n";
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - -1+2-1 |
| ユーザ | physics0523 |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 600 |
| コード長 | 763 Byte |
| 結果 | AC |
| 実行時間 | 11 ms |
| メモリ | 6228 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 600 / 600 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 00-sample-004.txt |
| All | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 00-sample-004.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00-sample-001.txt | AC | 1 ms | 3412 KiB |
| 00-sample-002.txt | AC | 1 ms | 3452 KiB |
| 00-sample-003.txt | AC | 1 ms | 3512 KiB |
| 00-sample-004.txt | AC | 1 ms | 3460 KiB |
| 01-001.txt | AC | 1 ms | 3460 KiB |
| 01-002.txt | AC | 9 ms | 4344 KiB |
| 01-003.txt | AC | 3 ms | 3920 KiB |
| 01-004.txt | AC | 8 ms | 5400 KiB |
| 01-005.txt | AC | 5 ms | 4084 KiB |
| 01-006.txt | AC | 3 ms | 3752 KiB |
| 01-007.txt | AC | 1 ms | 3552 KiB |
| 01-008.txt | AC | 10 ms | 5700 KiB |
| 01-009.txt | AC | 1 ms | 3412 KiB |
| 01-010.txt | AC | 6 ms | 4564 KiB |
| 01-011.txt | AC | 9 ms | 4716 KiB |
| 01-012.txt | AC | 11 ms | 6136 KiB |
| 01-013.txt | AC | 10 ms | 6148 KiB |
| 01-014.txt | AC | 11 ms | 6160 KiB |
| 01-015.txt | AC | 11 ms | 6140 KiB |
| 01-016.txt | AC | 11 ms | 6228 KiB |
| 01-017.txt | AC | 11 ms | 6220 KiB |
| 01-018.txt | AC | 11 ms | 6140 KiB |
| 01-019.txt | AC | 10 ms | 6152 KiB |