QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687625#1993. Equilateral Trianglesmakrav100 ✓213ms4776kbC++203.1kb2024-10-29 20:03:222024-10-29 20:03:23

Judging History

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

  • [2024-10-29 20:03:23]
  • 评测
  • 测评结果:100
  • 用时:213ms
  • 内存:4776kb
  • [2024-10-29 20:03:22]
  • 提交

answer

#include <bits/stdc++.h>
#include <cassert>

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 n; cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++) cin >> s[i];

    vector<vector<int>> pref_sum(2 * n, vector<int>(n + 1)), pref_diff(2 * n, vector<int>(n + 1));
    for (int sm = 0; sm <= 2 * n - 2; sm++) {
        for (int i = 0; i < n; i++) {
            pref_sum[sm][i + 1] = pref_sum[sm][i];
            if (sm >= i && sm - i < n && s[i][sm - i] == '*') {
                pref_sum[sm][i + 1]++;
            }
        }
    }
    for (int diff = -(n - 1); diff <= (n - 1); diff++) {
        for (int i = 0; i < n; i++) {
            pref_diff[diff + n][i + 1] = pref_diff[diff + n][i];
            if (i - diff >= 0 && i - diff < n && s[i][i - diff] == '*') {
                pref_diff[diff + n][i + 1]++;
            }
        }
    }

    auto get_seg_sum = [&](int sm, int li, int ri) {
        li = max(li, 0);
        ri = min(ri, n - 1);
        return max(0, pref_sum[sm][ri + 1] - pref_sum[sm][li]);
    };
    auto get_seg_diff = [&](int diff, int li, int ri) {
        li = max(li, 0); ri = min(ri, n - 1);
        return max(0, pref_diff[diff][ri + 1] - pref_diff[diff][li]);
    };

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (s[i][j] == '*') {
                int sm = i + j;
                for (int i1 = 0; i1 < n; i1++) {
                    if (i1 != i && sm - i1 >= 0 && sm - i1 < n && s[i1][sm - i1] == '*') {
                        int dist = abs(i1 - i) * 2;
                        if (sm + dist <= 2 * (n - 1)) {
                            ans += get_seg_sum(sm + dist, max(i, i1), min(i, i1) + dist);
                        }
                        if (sm - dist >= 0) { 
                            ans += get_seg_sum(sm - dist, max(i, i1) - dist, min(i, i1));
                        }
                    }
                }

                int diff = i - j;
                for (int i1 = 0; i1 < n; i1++) {
                    if (i1 - diff >= 0 && i1 - diff < n && i1 != i && s[i1][i1 - diff] == '*') {
                        int dist = 2 * abs(i1 - i);
                        if (diff - dist >= -(n - 1)) {
                            ans += get_seg_diff(diff - dist + n, max(i, i1) - dist + 1, min(i, i1) - 1);
                        }
                        if (diff + dist <= n - 1) {
                            ans += get_seg_diff(diff + dist + n, max(i1, i) + 1, min(i, i1) + dist - 1);
                        }
                    }
                }
            }   
        }
    }

    cout << ans / 2 << '\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

Pretests


Final Tests

Test #1:

score: 6.66667
Accepted
time: 0ms
memory: 3608kb

input:

3
*..
.*.
*..

output:

1

result:

ok single line: '1'

Test #2:

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

input:

50
*****.*********.******.*******.********.*.***.****
**.*****.*..******************.*.****.***.********
********.**.****.**.*******..*******.*..*.********
*****.**.****.********.*.**.*****.****.*.*********
*************.*.*.****.*****.*.*.**.***********.*.
******..*.**************.*********.*******...

output:

436237

result:

ok single line: '436237'

Test #3:

score: 6.66667
Accepted
time: 4ms
memory: 3656kb

input:

75
********..**...*********..******.*********************.**.**********.*.****
*******.**.***********************..*..***.****.*********...**********.*.*.
********.*********.**.******.***..*****.*************.*.******.*****...*.**
*****.****.**.***.****.***********************.****...********.******...

output:

2284176

result:

ok single line: '2284176'

Test #4:

score: 6.66667
Accepted
time: 5ms
memory: 3732kb

input:

100
.********.****.**.*******.*********..*.**************.**...***..*..**..**.*.*****..*.**.***.***.*.**
**************.**.****.**********.**********************.******.*****.***.*..****.**.*****.****.****
*********.*****.**.**..******.******.*****..**.**.***********.*******.******.*..**.*****.*****...

output:

7251584

result:

ok single line: '7251584'

Test #5:

score: 6.66667
Accepted
time: 15ms
memory: 4096kb

input:

125
.***************.*****.***.*.**.*.****....**.**.***.****.**.*.**.************.******..******.**********.*****************.***
...********..***.***.******.*********.*****.*.***.****.*****.**********.**.****.*.*******.*****.****.******.*************.*.*
*.*.**.*****.*.****..***.**.****************...

output:

17359107

result:

ok single line: '17359107'

Test #6:

score: 6.66667
Accepted
time: 26ms
memory: 3860kb

input:

150
*******..**.***********************..*****.*.*********.************************.***.**.*.*.*********.*******..***.****.*.*..*.*.*******.**********.***
*******************..*.*.***..***.***.***.************.******.**.*.*******.*******..*.**.****.***.*****..******.**.*****.*****************..**.**...

output:

35462232

result:

ok single line: '35462232'

Test #7:

score: 6.66667
Accepted
time: 41ms
memory: 3988kb

input:

175
*******....********.*.****..**********************.*.**..***.***..**.**...********..***.****.*****.*********....****.*********.**.**********.*****.***..****.*.**.***********.*
***.**.*************************..******.*****.****..******...***.*******.*..***....*****.**..*.************.***.*.***.....

output:

67053953

result:

ok single line: '67053953'

Test #8:

score: 6.66667
Accepted
time: 60ms
memory: 4296kb

input:

200
**.*******.*****************.******..*****.***.*.************.**********..****.**********..***.**********.**.****.***.....*****..*******.*..***.***.**.*****.**..*******.****..*****************.*******
..**.*.********.*.****.*.*********.**.**.****.**.*******.****.*.********.**.***.*.******.*****....

output:

114032086

result:

ok single line: '114032086'

Test #9:

score: 6.66667
Accepted
time: 88ms
memory: 4464kb

input:

225
*.********.****.*****.****.**..*.**..******.**.*.**********.*****.*****.***.*****.*.***.**.***..***.**.*******..**.**.*****..*.*******.****..***.*******.**..******.***********.************.****************.*.***.***.******.**
************.***.***.*.********.****..*.***.*****..***.**********.****...

output:

181903198

result:

ok single line: '181903198'

Test #10:

score: 6.66667
Accepted
time: 121ms
memory: 4288kb

input:

250
.*.********.*.**..*******.*...*******.************..***************.*.**.***.**.**.******************.*****.****.****..****.*.*..**************.*..*..**.**.**.****.****.***.**********.*..*******.************.*.****.*..*****.***.*.*..***.*********..**
***.**********.*.****.*******.*.**.******.***...

output:

277649728

result:

ok single line: '277649728'

Test #11:

score: 6.66667
Accepted
time: 163ms
memory: 4352kb

input:

275
********..**...*.********.**************************.*.******.*...********.*****.**.*******.**.***************.********.**..*.**********.**...*************.**.*****..*******.***.***.****.**.****.*.***.**.*******.*.*****.****.**.*******.*********.**.**.....**...**.********.*.
************.**.**.*...

output:

404298108

result:

ok single line: '404298108'

Test #12:

score: 6.66667
Accepted
time: 213ms
memory: 4776kb

input:

300
******.*************.**.***..**...****..*****.**.****.*.**.*********.***.**********.**.***.*******..****.****.*.**...***...****.**.***************.*********.*.*..**.**.****.***..****.*******.***.*.***.**...*..***.****.*.***.**.************..*.*.*********.**...**********.********..*..*.********.....

output:

569554456

result:

ok single line: '569554456'

Test #13:

score: 6.66667
Accepted
time: 213ms
memory: 4636kb

input:

300
*..*******.******.*****************.*********.********..********.******.*.*..****..*********************..****.**.**.***.*****...***.*************.*.*..****.***.**.*..*.*..************.***.**.**.************.*****.*****..*.*****.*.*.****.********.*****..**.*..*.***..*.***..***.*.********.******....

output:

575907601

result:

ok single line: '575907601'

Test #14:

score: 6.66667
Accepted
time: 212ms
memory: 4764kb

input:

300
**.***.*.**********.***..***..********.*****.*******.**.******.*************..****.*..********.***.***.*********.*****.****.*****.***...*.*******.*.****.**********.*****.*..***.*****.*******..*****.******..*.*.*.***...***..**.*******.*..*.*****..*.**..**********.*.**..*****..*****...******.***.*...

output:

575845244

result:

ok single line: '575845244'

Test #15:

score: 6.66667
Accepted
time: 213ms
memory: 4716kb

input:

300
***.********.*..******.********..******..***************.****.*.***..***.***********..******.***.*********.*.**********..******.**.*.*****.***..*.*.*...******.**.*****.***.****************.******..**********.***..*.**.********.**.******.******..****.*.***.**************..**.*.****.***.**********...

output:

574900414

result:

ok single line: '574900414'