QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#531079 | #5080. Folding Stick | Tiga_Pilot_2# | WA | 0ms | 3724kb | C++20 | 2.8kb | 2024-08-24 18:17:14 | 2024-08-24 18:17:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge {c b, e;};
sim > rge<c> range(c i, c j) {return rge<c>{i,j};}
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug{
~debug() {cerr << endl;}
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair <b, c> d) {
ris <<"(" <<d.fi <<", " <<d.se <<")";
}
sim dor(rge<c> d) {
*this << "[";
for(auto it=d.b;it!=d.e;++it) {
*this <<", " + 2*(it==d.b) <<*it;
}
ris << "]";
}
};
#define imie(...) "[" <<#__VA_ARGS__ ": " << (__VA_ARGS__) <<"]"
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = a; i > (b); --i)
#define ar array
#define sz(x) (int) (x).size()
#define pii pair<int,int>
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef pair<double,int> pdi;
typedef vector<int> vi;
#define all(x) (x).begin(), (x).end()
template<typename T>
void min_self(T& A, T B) {
A = min(A,B);
}
template<typename T>
void max_self(T& A, T B) {
A = max(A,B);
}
const int mxn=1e5;
int n;
int a[mxn];
int ans = 2e9;
vi pref;
bool chk(int r, int sm) {
if(r<0) return 1;
int pos = -1;
int li=0,ri=r;
int bwh = sm-a[r+1];
while(li<=ri) {
int mid = (li+ri)/2;
int sm2 = pref[r+1]-pref[mid];
if(sm2<=bwh) {
ri =mid-1;
} else if(sm2>sm) {
li = mid+1;
} else {
pos = mid;
li = mid+1;
}
}
if(pos==-1) return false;
while(pos>=0) {
int sm2 = pref[r+1]-pref[pos];
if(sm2>sm) break;
if(chk(pos-1,sm2)) return true;
pos--;
}
return false;
}
void solve() {
cin >>n;
rep(i,0,n) {
cin >>a[i];
}
pref.resize(n+1,0);
rep(i,0,n) {
pref[i+1] = pref[i]+a[i];
}
int suf = 0;
per(i,n-1,-1) {
int sm = 0;
per(j,i,-1) {
sm += a[j];
if(sm<=suf) continue;
if(sm>ans) break;
bool res = chk(j-1,sm);
if(res) {
// debug() <<imie(i) imie(j) imie(sm) imie(suf);
ans = sm;
break;
}
}
suf += a[i];
if(suf>ans) break;
}
cout <<ans <<"\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
input:
4 3 2 2 3
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
5 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3676kb
input:
7 1 3 2 3 4 2 2
output:
6
result:
ok single line: '6'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
9 5 6 3 4 8 8 2 2 5
output:
9
result:
ok single line: '9'
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3592kb
input:
10 5 6 3 4 8 6 2 1 8 5
output:
13
result:
wrong answer 1st lines differ - expected: '9', found: '13'