QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#406400#6661. 야유회nguyentunglamCompile Error//C++173.6kb2024-05-07 11:10:202024-05-07 11:10:21

Judging History

你现在查看的是最新测评结果

  • [2024-05-07 11:10:21]
  • 评测
  • [2024-05-07 11:10:20]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;

const int N = 1e3 + 10;

int mx[4] = {1, 1, -1, -1};
int my[4] = {1, -1, 1, -1};

int f[4][N][N];

int max_item_sum (vector<vector<int> > a) {
  int n = a.size();

  auto convert = [&] (int x) {
    return x == 1 ? 0 : n - 1;
  };

  auto check = [&] (int x) {
    return 0 <= x && x < n;
  };

  for(int k = 0; k < 4; k++) {
    for(int i = convert(mx[k]); check(i); i += mx[k]) for(int j = convert(my[k]); check(j); j += my[k]) {
      f[k][i][j] = -1e9;
      if (check(i - mx[k])) f[k][i][j] = max(f[k][i][j], f[k][i - mx[k]][j]);
      if (check(j - my[k])) f[k][i][j] = max(f[k][i][j], f[k][i][j - my[k]]);
      if (f[k][i][j] == -1e9) f[k][i][j] = 0;
      f[k][i][j] += a[i][j];
    }
  }

//  cout << f[0][2][2] << endl;

  int ans = -1e9;

//  cout << f[2][4][1] << endl;

  for(int col = 0; col < n; col++) {
    int mx = -1e9;
    int sum = 0;
    for(int row = 0; row < n; row++) {
      sum += a[row][col];
      if (check(col - 1) && check(col + 1)) ans = max(ans, f[2][row][col - 1] + f[3][row][col + 1] + sum + mx);
      if (check(row + 1) && check(col + 1)) ans = max(ans, f[2][row + 1][col] + f[3][row][col + 1] + sum + mx);
//      if (ans == -7) {
////        cout << f[2][row + 1][col] << " " << f[3][row][col + 1] << endl;
////        cout << row << " " << col << " " << mx << " " << " " << endl;
////        exit(0);
//      }
      if (check(row + 1) && check(col - 1)) ans = max(ans, f[2][row][col - 1] + f[3][row + 1][col] + sum + mx);
      sum -= a[row][col];

      if (check(col - 1) && check(col + 1)) mx = max(mx, f[0][row][col - 1] + f[1][row][col + 1] - sum);
      if (check(row - 1) && check(col + 1)) mx = max(mx, f[0][row - 1][col] + f[1][row][col + 1] - sum);
      if (check(row - 1) && check(col - 1)) mx = max(mx, f[0][row][col - 1] + f[1][row - 1][col] - sum);
      sum += a[row][col];
    }
  }

//  return ans;

  for(int row = 0; row < n; row++) {
    int mx = -1e9;
    int sum = 0;
    for(int col = 0; col < n; col++) {
      sum += a[row][col];
      if (check(row - 1) && check(row + 1)) ans = max(ans, f[1][row - 1][col] + f[3][row + 1][col] + sum + mx);
      if (check(row - 1) && check(col + 1)) ans = max(ans, f[1][row - 1][col] + f[3][row][col + 1] + sum + mx);
      if (check(row + 1) && check(col + 1)) ans = max(ans, f[1][row][col + 1] + f[3][row + 1][col] + sum + mx);
      sum -= a[row][col];
      if (check(row - 1) && check(row + 1)) mx = max(mx, f[0][row - 1][col] + f[2][row + 1][col] - sum);
      if (check(row - 1) && check(col - 1)) mx = max(mx, f[0][row - 1][col] + f[2][row][col - 1] - sum);
      if (check(col - 1) && check(row + 1)) mx = max(mx, f[0][row][col - 1] + f[2][row + 1][col] - sum);
      sum += a[row][col];
    }
  }

  for(int row = 1; row + 1 < n; row++) for(int col = 1; col + 1 < n; col++) {
    ans = max(ans, f[0][row - 1][col] + f[3][row + 1][col] + f[1][row][col + 1] + f[2][row][col - 1]);
    ans = max(ans, f[0][row][col - 1] + f[3][row][col + 1] + f[1][row - 1][col] + f[2][row + 1][col]);
  }

  return ans;
}

#ifdef ngu
int main() {

  freopen ("task.inp", "r", stdin);
  freopen ("task.out", "w", stdout);

//  cout << max_item_sum({{1, 1, -1, -1, 1}, {-1, 1, -1, 1, 1}, {1, 1, 1, 1, -1}, {1, -1,
//-1, 1, -1}, {1, -1, -1, 1, 1}});
//  exit(0);


  int n; cin >> n;

  vector<vector<int> > a (n, vector<int> (n));

  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) cin >> a[i][j];

  cout << max_item_sum(a);

}
#endif // ngu


Details

/usr/bin/ld: /tmp/cc1Jvzey.o: in function `main':
implementer.cpp:(.text.startup+0x113): undefined reference to `init()'
/usr/bin/ld: implementer.cpp:(.text.startup+0x922): undefined reference to `morning(int, int)'
/usr/bin/ld: implementer.cpp:(.text.startup+0xdce): undefined reference to `init()'
/usr/bin/ld: implementer.cpp:(.text.startup+0x110b): undefined reference to `morning(int, int)'
/usr/bin/ld: implementer.cpp:(.text.startup+0x1340): undefined reference to `afternoon(int, int, int)'
/usr/bin/ld: implementer.cpp:(.text.startup+0x1579): undefined reference to `evening(int, int, int)'
/usr/bin/ld: implementer.cpp:(.text.startup+0x1b5c): undefined reference to `afternoon(int, int, int)'
/usr/bin/ld: implementer.cpp:(.text.startup+0x1ba4): undefined reference to `evening(int, int, int)'
collect2: error: ld returned 1 exit status