답안 #519863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519863 2022-01-27T12:53:50 Z Hacv16 Nizin (COCI16_nizin) C++17
100 / 100
70 ms 6256 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

#define pb push_back
#define sz(x) (int) x.size()
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define dbg(x) cout << #x << ": " << "[ " << x << " ]\n"

int n, v[MAX], ans;

void setIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
}

int main(){
    setIO();

    cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> v[i];
    }

    int l = 1, r = n;
    int sl = 0, sr = 0;

    while(l < r){
        sl += v[l], sr += v[r];
        v[l] = 0, v[r] = 0; //avoid double-counting

        if(sl == sr){
            l++, r--;
            sl = sr = 0;
        }else if(sl > sr){
            r--, ans++;
        }else{
            l++, ans++;
        }
    }

    cout << ans << '\n';

    return 0;
}

 
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
    * brute force to find pattern?
    * sort?
    * graph?
    * WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 716 KB Output is correct
2 Correct 7 ms 848 KB Output is correct
3 Correct 5 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 2372 KB Output is correct
2 Correct 24 ms 2820 KB Output is correct
3 Correct 29 ms 3244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 4804 KB Output is correct
2 Correct 45 ms 5020 KB Output is correct
3 Correct 70 ms 5660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 6144 KB Output is correct
2 Correct 53 ms 6220 KB Output is correct
3 Correct 53 ms 6256 KB Output is correct