제출 #1320262

#제출 시각아이디문제언어결과실행 시간메모리
1320262kasamchi전선 연결 (IOI17_wiring)C++20
컴파일 에러
0 ms0 KiB
long long min_total_length(vector<int> r, vector<int> b) { int N = r.size() + b.size(); int ridx = 0, bidx = 0; vector<int> pos = {0}, col = {0}; while (ridx < r.size() || bidx < b.size()) { if (bidx == b.size()) { pos.push_back(r[ridx]); col.push_back(0); ridx++; } else if (ridx == r.size()) { pos.push_back(b[bidx]); col.push_back(1); bidx++; } else if (r[ridx] < b[bidx]) { pos.push_back(r[ridx]); col.push_back(0); ridx++; } else { pos.push_back(b[bidx]); col.push_back(1); bidx++; } } vector<long long> pre(N + 1); for (int i = 1; i <= N; i++) { pre[i] = pre[i - 1] + pos[i]; } vector<long long> dp(N + 1, (long long)1e18); for (int idx = 1; idx <= N; ) { int clb = idx, crb = idx; while (crb <= N && col[crb] == col[clb]) { crb++; } idx = crb; crb--; if (clb == 1) { continue; } int prb = clb - 1, plb = prb; while (plb >= 1 && col[plb] == col[prb]) { plb--; } plb++; for (int c = clb; c <= crb; c++) { int psz = prb - plb + 1, csz = c - clb + 1; long long sum = 0; sum += pre[c] - pre[clb - 1]; sum -= pre[prb] - pre[plb - 1]; if (psz <= csz) { sum -= pos[prb] * (csz - psz); } else { sum += pos[clb] * (psz - csz); } for (int i = 0; i < max(psz, csz); i++) { int p = plb + i; long long cur = (plb == 1 ? 0 : min(dp[p - 1], dp[p])); dp[c] = min(dp[c], cur + sum); if (i < max(psz, csz)) { sum += pos[plb + i]; if (psz - i > csz) { sum -= pos[clb]; } else { sum -= pos[prb]; } } if (plb == 1) { break; } } } } return dp[N]; }

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

wiring.cpp:1:28: error: 'vector' was not declared in this scope
    1 | long long min_total_length(vector<int> r, vector<int> b) {
      |                            ^~~~~~
wiring.cpp:1:35: error: expected primary-expression before 'int'
    1 | long long min_total_length(vector<int> r, vector<int> b) {
      |                                   ^~~
wiring.cpp:1:43: error: 'vector' was not declared in this scope
    1 | long long min_total_length(vector<int> r, vector<int> b) {
      |                                           ^~~~~~
wiring.cpp:1:50: error: expected primary-expression before 'int'
    1 | long long min_total_length(vector<int> r, vector<int> b) {
      |                                                  ^~~
wiring.cpp:1:56: error: expression list treated as compound expression in initializer [-fpermissive]
    1 | long long min_total_length(vector<int> r, vector<int> b) {
      |                                                        ^