제출 #1124487

#제출 시각아이디문제언어결과실행 시간메모리
1124487lmToT27Line Town (CCO23_day1problem3)C++20
3 / 25
17 ms836 KiB
#include <bits/stdc++.h> #define all(dataStructure) dataStructure.begin(),dataStructure.end() using namespace std; typedef long long ll; const int MAX = 1e5 + 3; const int inf = 1e9; const ll MOD[] = {1000000007, 998244353}; int n, h[MAX]; void Solve() { cin >> n; for (int i = 1; i <= n; i++) cin >> h[i]; int ans = inf; for (int negaNums = 0; negaNums <= n; negaNums++) { deque <int> t0, t1; for (int i = 1; i <= n; i++) { if (i & 1) { if (h[i] == 1) t0.push_back(i); else t1.push_back(i); } else { if (h[i] == -1) t0.push_back(i); else t1.push_back(i); } } int res = 0; for (int i = 1; i <= negaNums; i++) { auto &pos = (i & 1) ? t1 : t0; if (pos.empty()) { res = inf; break; } res += max(0, pos.front() - i); pos.pop_front(); } for (int i = negaNums + 1; i <= n; i++) { auto &pos = (i & 1) ? t0 : t1; if (pos.empty()) { res = inf; break; } res += max(0, pos.front() - i); pos.pop_front(); } ans = min(ans, res); } cout << (ans == inf ? -1 : ans); } int32_t main() { std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0); #define TASK "" if (fopen(TASK".INP", "r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } if (fopen("TASK.INP", "r")) { freopen("TASK.INP", "r", stdin); freopen("TASK.OUT", "w", stdout); } /* int TEST = 1; cin >> TEST; while (TEST--) */ Solve(); cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int32_t main()':
Main.cpp:65:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |                 freopen(TASK".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:66:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |                 freopen(TASK".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:70:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |                 freopen("TASK.INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:71:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |                 freopen("TASK.OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...