Submission #8574464


Source Code Expand

Copy
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[200010];

signed main(){
	cin>>N;
	int p=0,q=0;
	REP(i,N){
		cin>>A[i];
		q+=A[i];
	}
	int t=q;
	int m=INF;
	for(int i=0;i<N-1;i++){
		p+=A[i];
		q-=A[i];
		m=min(m,abs(p-q));
	}
	cout<<m<<endl;
	return 0;
}

Submission Info

Submission Time
Task B - Iron Bar Cutting
User mamime19
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1524 Byte
Status AC
Exec Time 86 ms
Memory 1792 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 20
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
in01.txt AC 1 ms 256 KB
in02.txt AC 1 ms 256 KB
in03.txt AC 1 ms 256 KB
in04.txt AC 1 ms 256 KB
in05.txt AC 1 ms 256 KB
in06.txt AC 1 ms 256 KB
in07.txt AC 82 ms 1792 KB
in08.txt AC 82 ms 1792 KB
in09.txt AC 82 ms 1792 KB
in10.txt AC 82 ms 1792 KB
in11.txt AC 82 ms 1792 KB
in12.txt AC 82 ms 1792 KB
in13.txt AC 82 ms 1792 KB
in14.txt AC 82 ms 1792 KB
in15.txt AC 82 ms 1792 KB
in16.txt AC 82 ms 1792 KB
in17.txt AC 86 ms 1792 KB
in18.txt AC 1 ms 256 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB