답안 #1093786

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093786 2024-09-27T12:49:52 Z ramzialoulou Nizin (COCI16_nizin) C++17
100 / 100
51 ms 6412 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef Ramzi
#include "debug.h"
#else
#define debug(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n == 1) {
    cout << 0 << "\n";
    return 0;
  }
  if (n == 2) {
    cout << (a[0] == a[1] ? 0 : 1) << "\n";
    return 0;
  }
  int l = 0, r = n - 1;
  int ans = 0;
  while (l < r) {
    if (a[l] != a[r]) {
      if (a[l] < a[r]) {
        while (l < n && a[l] < a[r]) {
          a[l + 1] += a[l];
          ++l;
          ++ans;
        }
      } else {
        while (r >= 0 && a[r] < a[l]) {
          a[r - 1] += a[r];
          ++ans;
          --r;
        }
      }
    } else {
      ++l, --r;
    }
  }
  cout << ans << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 860 KB Output is correct
2 Correct 4 ms 860 KB Output is correct
3 Correct 4 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2400 KB Output is correct
2 Correct 18 ms 2756 KB Output is correct
3 Correct 22 ms 3420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 4948 KB Output is correct
2 Correct 33 ms 5072 KB Output is correct
3 Correct 42 ms 5716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 6228 KB Output is correct
2 Correct 41 ms 6412 KB Output is correct
3 Correct 51 ms 6348 KB Output is correct