Submission #73094209
Source Code Expand
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
struct Init { Init() { ios::sync_with_stdio(0); cin.tie(0); } }init;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
#define rep(i,l,r) for (ll i = (ll)l; i < (ll)r; i++)
int main(){
Init();
ll N;
cin >> N;
vector<ll> A(N);
rep(i,0,N){
cin >> A[i];
}
sort(A.begin(), A.end());
if(N>2){
auto Iter = lower_bound(A.begin(), A.end() ,A[N-1]);
//最大長がそのまま残るパターン
int upper = Iter - A.begin() - 1; // 最大の一個前の値を指すインデックス
int i=0;
int is_ok = false;
if(upper % 2 !=0){
while(true){
if(i >= upper - i){
if(upper)
is_ok = true;
break;
}
if(A[N-1] != A[i] + A[upper - i]) break;
i++;
}
}
//最大長が変わるパターン
ll x = A[0] + A[N-1];
i=0;
bool is_ok_2 = false;
while(true){
if(i >= N-i){
// Nが奇数のときは中間の値をそのまま比較する
if(N%2==1){
if(x != A[N/2]) break;
}
is_ok_2 = true;
break;
}
if(x != A[i] + A[N-i-1]){
break;
}
i++;
}
string out = "";
if(is_ok){
out += to_string(A[N-1]);
}
if(is_ok_2){
if(is_ok){ out += " ";}
out += to_string(x);
}
cout << out << endl;
}
else if(N==2){
if(A[0] == A[1]){
cout << to_string(A[0]) + " ";
}
cout << A[0] + A[1] << endl;
}
else{
cout << A[0] << endl;
}
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - AtCoder Riko |
| User | MatsumotoT |
| Language | C++23 (GCC 15.2.0) |
| Score | 350 |
| Code Size | 2107 Byte |
| Status | AC |
| Exec Time | 34 ms |
| Memory | 5772 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 350 / 350 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 0_sample_1.txt, 0_sample_2.txt, 0_sample_3.txt |
| All | 0_sample_1.txt, 0_sample_2.txt, 0_sample_3.txt, 1_1.txt, 1_2.txt, 1_3.txt, 1_4.txt, 1_5.txt, 2_1.txt, 2_2.txt, 2_3.txt, 2_4.txt, 3_1.txt, 3_2.txt, 3_3.txt, 3_4.txt, 3_5.txt, 3_6.txt, 4_1.txt, 4_2.txt, 4_3.txt, 4_4.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 0_sample_1.txt | AC | 1 ms | 3644 KiB |
| 0_sample_2.txt | AC | 1 ms | 3504 KiB |
| 0_sample_3.txt | AC | 1 ms | 3484 KiB |
| 1_1.txt | AC | 29 ms | 5772 KiB |
| 1_2.txt | AC | 29 ms | 5760 KiB |
| 1_3.txt | AC | 28 ms | 5692 KiB |
| 1_4.txt | AC | 28 ms | 5688 KiB |
| 1_5.txt | AC | 28 ms | 5752 KiB |
| 2_1.txt | AC | 34 ms | 5712 KiB |
| 2_2.txt | AC | 33 ms | 5692 KiB |
| 2_3.txt | AC | 33 ms | 5688 KiB |
| 2_4.txt | AC | 33 ms | 5748 KiB |
| 3_1.txt | AC | 34 ms | 5764 KiB |
| 3_2.txt | AC | 33 ms | 5676 KiB |
| 3_3.txt | AC | 32 ms | 5752 KiB |
| 3_4.txt | AC | 20 ms | 5692 KiB |
| 3_5.txt | AC | 1 ms | 3496 KiB |
| 3_6.txt | AC | 28 ms | 5676 KiB |
| 4_1.txt | AC | 11 ms | 5688 KiB |
| 4_2.txt | AC | 17 ms | 5744 KiB |
| 4_3.txt | AC | 1 ms | 3592 KiB |
| 4_4.txt | AC | 1 ms | 3608 KiB |