제출 #212804

#제출 시각아이디문제언어결과실행 시간메모리
212804SortingNafta (COI15_nafta)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int kN = 2007; template<class T> void max_check(T &a, const T &b){ a = a >= b ? a : b; } template<class T> void min_check(T &a, const T &b){ a = a <= b ? a : b; } int r, s; string land[kN]; bool vis[kN][kN]; vector<array<int, 3>> ranges; int dp[kN][kN], sum[kN][kN], r_sum[kN], add[kN]; array<int, 3> dfs(int x, int y){ array<int, 3> ret{y, y, (land[x][y] != '.') ? (land[x][y] - '0') : 0}; vis[x][y] = true; array<pair<int, int>, 4> adj{pair{x + 1, y}, {x - 1, y}, {x, y - 1}, {x, y + 1}}; for(pair<int, int> to: adj){ if(to.first < 0 || to.first >= r || to.second < 0 || to.second >= s) continue; if(land[to.first][to.second] == '.' || vis[to.first][to.second]) continue; array<int, 3> curr = dfs(to.first, to.second); min_check(ret[0], curr[0]); max_check(ret[1], curr[1]); ret[2] += curr[2]; } return ret; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> r >> s; for(int i = 0; i < r; ++i) cin >> land[i]; for(int i = 0; i < r; ++i) for(int j = 0; j < s; ++j) if(land[i][j] != '.' && !vis[i][j]) ranges.push_back(dfs(i, j)); sort(ranges.begin(), ranges.end()); for(int i = s - 1, idx = ranges.size() - 1; i >= 0; --i){ while(idx >= 0 && ranges[idx][0] >= i){ add[ranges[idx][0]] += ranges[idx][2]; add[ranges[idx][1] + 1] -= ranges[idx][2]; --idx; } int curr_sum = 0; for(int j = i; j <= s - 1; ++j){ curr_sum += add[j]; sum[i][j] = curr_sum; //cout << "sum[" << i << "][" << j << "] = " << sum[i][j] << endl; } } for(int i = 0; i <= s; ++i) dp[0][i] = 0; for(int k = 1; k <= s; ++k){ dp[k][r] = 0; for(int pos = s - 1; pos >= 0; --pos){ dp[k][pos] = 0; for(int nxt = pos; nxt <= s - 1; ++nxt) max_check(dp[k][pos], dp[k - 1][nxt + 1] + sum[pos][nxt]); //cout << "dp[" << k << "][" << pos << "] = " << dp[k][pos] << endl; } } for(int k = 1; k <= s; ++k) cout << dp[k][0] << "\n"; }

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

nafta.cpp: In function 'std::array<int, 3> dfs(int, int)':
nafta.cpp:28:35: error: missing template arguments before '{' token
  array<pair<int, int>, 4> adj{pair{x + 1, y}, {x - 1, y}, {x, y - 1}, {x, y + 1}};
                                   ^
nafta.cpp:28:35: error: expected '}' before '{' token
nafta.cpp:28:35: error: expected ',' or ';' before '{' token
nafta.cpp:28:45: error: expected primary-expression before ',' token
  array<pair<int, int>, 4> adj{pair{x + 1, y}, {x - 1, y}, {x, y - 1}, {x, y + 1}};
                                             ^
nafta.cpp:28:47: error: expected primary-expression before '{' token
  array<pair<int, int>, 4> adj{pair{x + 1, y}, {x - 1, y}, {x, y - 1}, {x, y + 1}};
                                               ^
nafta.cpp:28:57: error: expected primary-expression before ',' token
  array<pair<int, int>, 4> adj{pair{x + 1, y}, {x - 1, y}, {x, y - 1}, {x, y + 1}};
                                                         ^
nafta.cpp:28:59: error: expected primary-expression before '{' token
  array<pair<int, int>, 4> adj{pair{x + 1, y}, {x - 1, y}, {x, y - 1}, {x, y + 1}};
                                                           ^
nafta.cpp:28:69: error: expected primary-expression before ',' token
  array<pair<int, int>, 4> adj{pair{x + 1, y}, {x - 1, y}, {x, y - 1}, {x, y + 1}};
                                                                     ^
nafta.cpp:28:71: error: expected primary-expression before '{' token
  array<pair<int, int>, 4> adj{pair{x + 1, y}, {x - 1, y}, {x, y - 1}, {x, y + 1}};
                                                                       ^
nafta.cpp:25:16: warning: unused variable 'ret' [-Wunused-variable]
  array<int, 3> ret{y, y, (land[x][y] != '.') ? (land[x][y] - '0') : 0};
                ^~~
nafta.cpp:28:27: warning: unused variable 'adj' [-Wunused-variable]
  array<pair<int, int>, 4> adj{pair{x + 1, y}, {x - 1, y}, {x, y - 1}, {x, y + 1}};
                           ^~~
nafta.cpp:28:81: warning: no return statement in function returning non-void [-Wreturn-type]
  array<pair<int, int>, 4> adj{pair{x + 1, y}, {x - 1, y}, {x, y - 1}, {x, y + 1}};
                                                                                 ^
nafta.cpp: At global scope:
nafta.cpp:29:2: error: expected unqualified-id before 'for'
  for(pair<int, int> to: adj){
  ^~~
nafta.cpp:41:2: error: expected unqualified-id before 'return'
  return ret;
  ^~~~~~
nafta.cpp:42:1: error: expected declaration before '}' token
 }
 ^