제출 #469072

#제출 시각아이디문제언어결과실행 시간메모리
469072ntabc05101이상적인 도시 (IOI12_city)C++14
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; const int mod = 1e9; int N; long long res; vector< vector<int> > adj; vector<int> w; int dfs(int u, int p) { int W = w[u]; for (auto &to: adj[u]) { if (to != p) { int v = dfs(to, u); (res += 1ll * v * (N - v)) %= mod; W += v; } } return W; } int DistanceSum(int N, int *X, int *Y) { ::N = N; int mnX = (1LL << 31) - 2, mnY = mnX, mxX = 0, mxY = 0; for (int i = 0; i < N; i++) { mnX = min(mnX, X[i]); mnY = min(mnY, Y[i]); mxX = max(mxX, X[i]); mxY = max(mxY, Y[i]); } mxX -= mnX - 1; mxY -= mnY - 1; for (int i = 0; i < N; i++) { X[i] -= mnX; Y[i] -= mnY; } res = 0; vector<int> c, d; vector< vector<int> > pts; for (int e = 0; e < 2; e++) { pts.assign(mxX, vector<int>()); for (int i = 0; i < N; i++) { pts[X[i]].push_back(Y[i]); } int cur = 0, cnt = 0; w.clear(); c.clear(); d.clear(); adj.clear(); adj.push_back(vector<int>()); for (int i = 0; i < mxX; i++) { sort(pts[i].begin(), pts[i].end()); int k = 0; d.clear(); for (int j = 0; j < pts[i].size(); j++) { d.push_back(cur); cnt++; if (i > 0) { while (k < pts[i - 1].size() && pts[i - 1][k] < pts[i][j]) { k++; } if (k < pts[i - 1].size() && pts[i - 1][k] == pts[i][j]) { adj[cur].push_back(c[k]); adj[c[k]].push_back(cur); } } if (j == pts[i].size() - 1 || pts[i][j] + 1 < pts[i][j + 1]) { w.push_back(cnt); cur++; cnt = 0; adj.push_back(vector<int>()); } } swap(c, d); } for (auto& ad: adj) { sort(ad.begin(), ad.end()); ad.resize(unique(ad.begin(), ad.end()) - ad.begin()); /*for (auto& _: ad) { cout << _ << " "; } cout << "\n";*/ } dfs(0, -1); for (int i = 0; i < N; i++) { swap(X[i], Y[i]); } swap(mxX, mxY); } return res; } int main() { cin.tie(0)->sync_with_stdio(0); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int N; cin >> N; int *X = new int[N], *Y = new int[N]; for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i]; } cout << DistanceSum(N, X, Y) << "\n"; return 0; } /* 11 2 5 2 6 3 3 3 6 4 3 4 4 4 5 4 6 5 3 5 4 5 6 */

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

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |    for (int j = 0; j < pts[i].size(); j++) {
      |                    ~~^~~~~~~~~~~~~~~
city.cpp:56:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |      while (k < pts[i - 1].size() && pts[i - 1][k] < pts[i][j]) {
      |             ~~^~~~~~~~~~~~~~~~~~~
city.cpp:59:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |      if (k < pts[i - 1].size() && pts[i - 1][k] == pts[i][j]) {
      |          ~~^~~~~~~~~~~~~~~~~~~
city.cpp:64:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |     if (j == pts[i].size() - 1 || pts[i][j] + 1 < pts[i][j + 1]) {
      |         ~~^~~~~~~~~~~~~~~~~~~~
city.cpp: In function 'int main()':
city.cpp:96:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |  freopen("input.txt", "r", stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
city.cpp:97:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |  freopen("output.txt", "w", stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccB3xijJ.o: in function `main':
city.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccrSw4SJ.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status