Submission #465165

# Submission time Handle Problem Language Result Execution time Memory
465165 2021-08-15T09:33:59 Z zxcvbnm Treasure (different grader from official contest) (CEOI13_treasure2) C++14
100 / 100
6 ms 972 KB
#include "treasure.h"
#include <bits/stdc++.h>
using namespace std;
int n;
bool ans[105][105];
int pref[105][105];
map<array<int, 4>, int> call;
int query(int x1, int y1, int x2, int y2) {
    if (x1 > x2) swap(x1, x2);
    if (y1 > y2) swap(y1, y2);
//    cerr << x1 << " " << y1 << " " << x2 << " " << y2 << "\n";
    if (x1 <= 0 || x2 <= 0 || x2 > n || x1 > n || y1 <= 0 || y1 > n || y2 <= 0 || y2 > n) return 0;
    if (call.count({x1, y1, x2, y2})) {
        return call[{x1, y1, x2, y2}];
    }
    return call[{x1, y1, x2, y2}] = countTreasure(x1, y1, x2, y2);
}

int quadrant(int x, int y, int dx[], int dy[]) {
    vector<int> poss;
    for(int i = 0; i < 4; i++) {
        poss.push_back(abs(dx[i]-x) * abs(dy[i]-y));
    }
    return max_element(poss.begin(), poss.end()) - poss.begin();
}
void findTreasure (int N) {
    n = N;

    int dx[] = {1, n, 1, n};
    int dy[] = {1, 1, n, n};

    int mid = n/2;
    for(int i = n; i >= 1; i--) {
        for(int j = n; j >= 1; j--) {
            int idx = quadrant(i, j, dx, dy);
            if (i > mid && j > mid) {
                pref[i][j] = query(1, 1, i, j);
            } else if (i > mid) {
                pref[i][j] = pref[i][n] - query(1, j+1, i, n);
            } else if (j > mid) {
                pref[i][j] = pref[n][j] - query(i+1, 1, n, j);
            } else {
                pref[i][j] = pref[n][j] + pref[i][n] + query(i+1, j+1, n, n) - pref[n][n];
            }
        }
    }

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            ans[i][j] = (pref[i][j] - pref[i-1][j] - pref[i][j-1] + pref[i-1][j-1]);
            if (ans[i][j]) {
                Report(i, j);
            }
//            cerr << ans[i][j] << " ";
        }
//        cerr << "\n";
    }

}

Compilation message

treasure.cpp: In function 'void findTreasure(int)':
treasure.cpp:35:17: warning: unused variable 'idx' [-Wunused-variable]
   35 |             int idx = quadrant(i, j, dx, dy);
      |                 ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct - N = 5, K = 289, score = 10
2 Correct 1 ms 332 KB Output is correct - N = 10, K = 4475, score = 10
3 Correct 1 ms 332 KB Output is correct - N = 15, K = 22289, score = 10
4 Correct 1 ms 332 KB Output is correct - N = 16, K = 28928, score = 10
5 Correct 2 ms 460 KB Output is correct - N = 55, K = 4005289, score = 10
6 Correct 3 ms 588 KB Output is correct - N = 66, K = 8305803, score = 10
7 Correct 3 ms 716 KB Output is correct - N = 77, K = 15383161, score = 10
8 Correct 6 ms 844 KB Output is correct - N = 88, K = 26244416, score = 10
9 Correct 6 ms 972 KB Output is correct - N = 99, K = 42032201, score = 10
10 Correct 6 ms 972 KB Output is correct - N = 100, K = 43760000, score = 10