QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#557043#360. Cultivationmakrav5 299ms3820kbC++201.9kb2024-09-11 00:53:472024-09-11 00:53:48

Judging History

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

  • [2024-09-11 00:53:48]
  • 评测
  • 测评结果:5
  • 用时:299ms
  • 内存:3820kb
  • [2024-09-11 00:53:47]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second

void solve() {
    int h, w, n; cin >> h >> w >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {cin >> a[i].first >> a[i].second; a[i].first--; a[i].second--; }
    int ans = 1e9;
    for (int up = 0; up < h; up++) {
        for (int down = 0; down < h; down++) {
            for (int left = 0; left < w; left++) {
                for (int right = 0; right < w; right++) {
                    vector<vector<int>> us(h, vector<int>(w));
                    for (int i = 0; i < n; i++) {
                        for (int j=-up;j<=down;j++){
                            for (int k = -left; k <= right; k++) {
                                if (a[i].first + j >= 0 && a[i].first + j < h && a[i].second + k >= 0 && a[i].second + k < w) us[a[i].first + j][a[i].second + k] = 1;
                            }
                        }
                    }
                    //cout<<up<<' '<<down<<' '<<left<<' '<<right<<'\n';
                    bool good = true;
                    for(int i=0;i<h;i++){
                        for(int j=0;j<w;j++){
                            if (!us[i][j]){
                                good = false;
                                break;
                            }
                        }
                    }
                    if(good)ans=min(ans,up+down+left+right);
                }
            }
        }
    }
    cout << ans << '\n';
}

signed main() {
    int tt = 1;
    #ifdef LOCAL 
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> tt;
    #else
        ios::sync_with_stdio(false); 
        cin.tie(0); cout.tie(0);
    #endif

    while (tt--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 1ms
memory: 3560kb

input:

2 4
2
1 1
1 4

output:

3

result:

ok single line: '3'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3568kb

input:

4 1
1
2 1

output:

3

result:

ok single line: '3'

Test #3:

score: 5
Accepted
time: 0ms
memory: 3820kb

input:

3 3
3
1 2
1 3
3 3

output:

3

result:

ok single line: '3'

Test #4:

score: 5
Accepted
time: 0ms
memory: 3596kb

input:

2 2
1
1 2

output:

2

result:

ok single line: '2'

Test #5:

score: 5
Accepted
time: 1ms
memory: 3628kb

input:

4 4
10
4 2
2 3
2 4
4 1
1 2
2 1
4 3
3 3
3 1
1 4

output:

2

result:

ok single line: '2'

Test #6:

score: 5
Accepted
time: 0ms
memory: 3504kb

input:

4 4
1
4 1

output:

6

result:

ok single line: '6'

Test #7:

score: 5
Accepted
time: 0ms
memory: 3560kb

input:

4 4
3
2 2
3 3
1 4

output:

5

result:

ok single line: '5'

Test #8:

score: 5
Accepted
time: 1ms
memory: 3560kb

input:

4 4
15
4 3
2 4
4 4
4 1
3 3
1 2
3 1
2 1
3 4
3 2
4 2
2 3
1 3
2 2
1 4

output:

1

result:

ok single line: '1'

Test #9:

score: 5
Accepted
time: 0ms
memory: 3564kb

input:

4 3
3
2 1
2 3
4 1

output:

3

result:

ok single line: '3'

Test #10:

score: 5
Accepted
time: 0ms
memory: 3564kb

input:

4 4
2
3 4
2 4

output:

5

result:

ok single line: '5'

Test #11:

score: 5
Accepted
time: 0ms
memory: 3560kb

input:

2 4
1
1 2

output:

4

result:

ok single line: '4'

Test #12:

score: 5
Accepted
time: 0ms
memory: 3508kb

input:

3 3
4
2 1
1 1
3 2
3 1

output:

2

result:

ok single line: '2'

Test #13:

score: 5
Accepted
time: 0ms
memory: 3660kb

input:

3 4
3
1 4
3 3
3 4

output:

4

result:

ok single line: '4'

Test #14:

score: 5
Accepted
time: 0ms
memory: 3596kb

input:

3 3
2
2 1
3 3

output:

4

result:

ok single line: '4'

Test #15:

score: 5
Accepted
time: 1ms
memory: 3560kb

input:

4 4
2
2 4
3 1

output:

6

result:

ok single line: '6'

Test #16:

score: 5
Accepted
time: 0ms
memory: 3564kb

input:

4 4
3
2 2
2 1
4 2

output:

4

result:

ok single line: '4'

Subtask #2:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Test #17:

score: 10
Accepted
time: 299ms
memory: 3804kb

input:

15 15
20
6 13
14 4
11 13
15 3
12 4
10 4
11 6
8 9
12 12
2 15
4 3
8 15
8 4
3 1
5 10
11 12
8 7
13 10
11 4
1 3

output:

13

result:

ok single line: '13'

Test #18:

score: 0
Time Limit Exceeded

input:

25 25
66
24 6
12 18
11 2
24 18
6 9
20 6
15 19
17 2
15 9
15 20
18 9
5 19
9 2
6 12
22 16
6 2
1 5
14 24
12 21
17 24
10 15
21 1
20 22
11 24
11 4
6 21
18 12
25 20
16 3
18 16
6 4
20 9
6 15
24 14
3 20
9 9
25 9
18 6
4 16
12 7
14 22
20 25
24 10
11 14
17 6
23 23
21 12
18 22
8 23
1 11
17 18
8 5
3 7
1 17
8 12
4...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Memory Limit Exceeded

Test #45:

score: 0
Memory Limit Exceeded

input:

1000000000 1000000000
17
822413671 70423910
260075513 431043546
300945721 793553248
142848049 163787897
392462410 831950868
699005697 111397300
444396260 130450496
642691616 595456084
467968916 463598810
159764248 611476406
929313754 539645102
365153650 964108073
906780716 373514044
970118116 655138...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%