답안 #47669

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
47669 2018-05-06T08:14:17 Z maksim_gaponov Cultivation (JOI17_cultivation) C++14
5 / 100
2000 ms 1016 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

void openFiles() {
#ifdef KEK
	assert(freopen("input.txt", "r", stdin));
	assert(freopen("output.txt", "w", stdout));
#endif
}

void IOoptimize() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

struct Action {
    int time;
    int l, r;
    int type;
    int id;
};

bool operator< (const Action &a1, const Action &a2) {
    if (a1.time == a2.time)
        return a1.id < a2.id;
    return a1.time < a2.time;
}

const int MAXN = 300;
const int MAX = 40;
int x[MAXN], y[MAXN];
int f[MAX];

int main() {
	openFiles();
	IOoptimize();
    int r, c;
    cin >> r >> c;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    int ans = INT_MAX;
    int cnt[4];
    for (cnt[0] = 0; cnt[0] <= MAX; cnt[0]++)
    for (cnt[1] = 0; cnt[1] <= MAX; cnt[1]++)
    for (cnt[2] = 0; cnt[2] <= MAX; cnt[2]++)
    for (cnt[3] = 0; cnt[3] <= MAX; cnt[3]++) {
        int new_ans = cnt[0] + cnt[1] + cnt[2] + cnt[3];
        if (ans <= new_ans)
            continue;
        memset(f, 0, sizeof(f));
        vector<Action> v;
        for (int i = 0; i < n; i++) {
            Action act;
            act.id = i;
            act.time = max(y[i] - cnt[1], 0);
            act.l = max(x[i] - cnt[0], 0);
            act.r = min(x[i] + cnt[2], r - 1);
            act.type = 1;
            v.push_back(act);
            act.time = min(y[i] + cnt[3] + 1, c);
            act.type = -1;
            v.push_back(act);
        }
        sort(v.begin(), v.end());
        int last = 0;
        int sq = 0;
        for (auto act : v) {
            //cout << act.time << " " << act.l << " " << act.r << " " << act.type << "\n";
            int active_count = 0;
            for (int i = 0; i < r; i++)
                if (f[i])
                    active_count++;
            sq += active_count * (act.time - last);
            last = act.time;
            for (int i = act.l; i <= act.r; i++)
                f[i] += act.type;
        }
        //cout << sq << "\n";
        //cout << "--/--\n";
        if (sq == r * c)
            ans = new_ans;
    }
    cout << ans;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 16 ms 620 KB Output is correct
3 Correct 9 ms 620 KB Output is correct
4 Correct 6 ms 620 KB Output is correct
5 Correct 7 ms 648 KB Output is correct
6 Correct 34 ms 768 KB Output is correct
7 Correct 8 ms 768 KB Output is correct
8 Correct 8 ms 796 KB Output is correct
9 Correct 37 ms 796 KB Output is correct
10 Correct 23 ms 796 KB Output is correct
11 Correct 6 ms 796 KB Output is correct
12 Correct 5 ms 920 KB Output is correct
13 Correct 9 ms 960 KB Output is correct
14 Correct 20 ms 960 KB Output is correct
15 Correct 23 ms 960 KB Output is correct
16 Correct 39 ms 960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 16 ms 620 KB Output is correct
3 Correct 9 ms 620 KB Output is correct
4 Correct 6 ms 620 KB Output is correct
5 Correct 7 ms 648 KB Output is correct
6 Correct 34 ms 768 KB Output is correct
7 Correct 8 ms 768 KB Output is correct
8 Correct 8 ms 796 KB Output is correct
9 Correct 37 ms 796 KB Output is correct
10 Correct 23 ms 796 KB Output is correct
11 Correct 6 ms 796 KB Output is correct
12 Correct 5 ms 920 KB Output is correct
13 Correct 9 ms 960 KB Output is correct
14 Correct 20 ms 960 KB Output is correct
15 Correct 23 ms 960 KB Output is correct
16 Correct 39 ms 960 KB Output is correct
17 Correct 20 ms 960 KB Output is correct
18 Correct 89 ms 960 KB Output is correct
19 Correct 906 ms 1000 KB Output is correct
20 Correct 77 ms 1000 KB Output is correct
21 Execution timed out 2068 ms 1000 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 16 ms 620 KB Output is correct
3 Correct 9 ms 620 KB Output is correct
4 Correct 6 ms 620 KB Output is correct
5 Correct 7 ms 648 KB Output is correct
6 Correct 34 ms 768 KB Output is correct
7 Correct 8 ms 768 KB Output is correct
8 Correct 8 ms 796 KB Output is correct
9 Correct 37 ms 796 KB Output is correct
10 Correct 23 ms 796 KB Output is correct
11 Correct 6 ms 796 KB Output is correct
12 Correct 5 ms 920 KB Output is correct
13 Correct 9 ms 960 KB Output is correct
14 Correct 20 ms 960 KB Output is correct
15 Correct 23 ms 960 KB Output is correct
16 Correct 39 ms 960 KB Output is correct
17 Correct 20 ms 960 KB Output is correct
18 Correct 89 ms 960 KB Output is correct
19 Correct 906 ms 1000 KB Output is correct
20 Correct 77 ms 1000 KB Output is correct
21 Execution timed out 2068 ms 1000 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 16 ms 620 KB Output is correct
3 Correct 9 ms 620 KB Output is correct
4 Correct 6 ms 620 KB Output is correct
5 Correct 7 ms 648 KB Output is correct
6 Correct 34 ms 768 KB Output is correct
7 Correct 8 ms 768 KB Output is correct
8 Correct 8 ms 796 KB Output is correct
9 Correct 37 ms 796 KB Output is correct
10 Correct 23 ms 796 KB Output is correct
11 Correct 6 ms 796 KB Output is correct
12 Correct 5 ms 920 KB Output is correct
13 Correct 9 ms 960 KB Output is correct
14 Correct 20 ms 960 KB Output is correct
15 Correct 23 ms 960 KB Output is correct
16 Correct 39 ms 960 KB Output is correct
17 Correct 20 ms 960 KB Output is correct
18 Correct 89 ms 960 KB Output is correct
19 Correct 906 ms 1000 KB Output is correct
20 Correct 77 ms 1000 KB Output is correct
21 Execution timed out 2068 ms 1000 KB Time limit exceeded
22 Halted 0 ms 0 KB -