제출 #124530

#제출 시각아이디문제언어결과실행 시간메모리
124530deinfreund과수원 (NOI14_orchard)C++14
13 / 25
543 ms165116 KiB
#include <bits/stdc++.h>

using namespace std;

int solve1D(vector<int> vals){
  vector<int> sums(vals.size());
  int totalTrees;

  for (int x= 0; x < vals.size(); x++){
    /*cin >> vals[x][y];
    totalTrees[y] += vals[x][y];
    vals[x][y] = 2 * vals[x][y] - 1;
    if (x > 0) sums[x][y] += sums[x-1][y];
    sums[x][y] += vals[x][y];*/
  }
}

int main(){
  int h, w;
  cin >> h >> w;
  vector<vector<int> > sums(w, vector<int>(h));
  vector<vector<int>> totalTrees(w, vector<int>(h));
  vector<vector<int> > vals(w, vector<int>(h));
  for (int y = 0; y< h; y++){
    for (int x= 0; x < w; x++){
      cin >> vals[x][y];
      totalTrees[x][y] += vals[x][y];
      if (x > 0) totalTrees[x][y] += totalTrees[x-1][y];
      vals[x][y] = 2 * vals[x][y] - 1;
      if (x > 0) sums[x][y] += sums[x-1][y];
      sums[x][y] += vals[x][y];
    }
  }
  for (int x = 0; x < w; x++){
    for (int y = 1; y < h; y++){
      sums[x][y] += sums[x][y - 1];
      totalTrees[x][y] += totalTrees[x][y - 1];
    }
  }
  for (int y = 0; y< h; y++){
    int minv = 0;
    int minx = -1;
    int bests = 0;
    int beste = 0;
    int bestv = 0;
    for (int x= 0; x < w; x++){
      if (sums[x][y] < minv){
	minv = sums[x][y];
	minx = x;
      }
      int v = sums[x][y] - minv;
      if (v > bestv){
	bestv = v;
	bests = minx;
	beste = x;
      }
    }
    //    cout << bests << " - " << beste << ": " << bestv << endl;
    cout << totalTrees[w - 1][y] - 2*(totalTrees[beste][y] - (bests < 0 ? 0 : totalTrees[bests][y])) + beste - bests << endl;
  }
}

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

orchard.cpp: In function 'int solve1D(std::vector<int>)':
orchard.cpp:9:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int x= 0; x < vals.size(); x++){
                  ~~^~~~~~~~~~~~~
orchard.cpp:7:7: warning: unused variable 'totalTrees' [-Wunused-variable]
   int totalTrees;
       ^~~~~~~~~~
orchard.cpp:16:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#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...