CSES - Datatähti 2023 alku - Results
Submission details
Task:Ruudukko
Sender:Kemm1706
Submission time:2022-12-03 16:33:35 +0200
Language:C++11
Status:READY
Result:28
Feedback
groupverdictscore
#1ACCEPTED28
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.00 s1, 2, 3details
#3ACCEPTED0.00 s1, 2, 3details
#4ACCEPTED0.01 s2, 3details
#50.01 s2, 3details
#60.01 s2, 3details
#70.01 s3details
#80.01 s3details
#90.01 s3details

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

struct Sq
{
    LL val, x, y;
};

bool SoSanh(Sq a, Sq b)
{
    return a.val < b.val;
}

LL Cal(LL a[100][100], LL x, LL y, LL n)
{
    LL r, ans = 0;
    for(r = 0; r < x; r++)
        ans += a[r][y];
    for(r = x + 1; r < n; r++)
        ans += a[r][y];
    for(r = 0; r < y; r++)
        ans += a[x][r];
    for(r = y + 1; r < n; r++)
        ans += a[x][r];
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    static LL a[100][100];
    static LL draft[100][100];
    static Sq k[10000];
    LL n, i, j, m = 0, s, ans = 0;
    cin >> n;
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++)
        {
            cin >> k[m].val;
            k[m].x = i;
            k[m].y = j;
            m++;
        }
    sort(k, k + m, SoSanh);
    i = 0;
    while(i < m && j < m)
    {
        j = i;
        vector <pair<LL, LL>> v;
        while(k[j].val == k[i].val && j < m)
        {
            v.push_back({k[j].x, k[j].y});
            draft[k[j].x][k[j].y] = Cal(a, k[j].x, k[j].y, n);
            draft[k[j].x][k[j].y]++;
            j++;
        }
        i = j;
        s = v.size();
        for(j = 0; j < s; j++)
            a[v[j].first][v[j].second] = draft[v[j].first][v[j].second];
    }
    /*for(i = 0; i < n; i++)
    {
        for(j = 0; j < n; j++)
            cout << a[i][j];
        cout << "\n";
    }*/
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++)
            ans += a[i][j];
    cout << ans;
    return 0;
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
1 1 1
1 1 1
1 1 1

correct output
9

user output
9

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
1 2 3
6 5 4
7 8 9

correct output
135

user output
135

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
3
7 8 1
4 5 4
3 9 6

correct output
57

user output
57

Test 4

Group: 2, 3

Verdict: ACCEPTED

input
100
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
10000

user output
10000

Test 5

Group: 2, 3

Verdict:

input
100
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
187458477

user output
-2988340646529634229

Test 6

Group: 2, 3

Verdict:

input
100
2995 8734 1018 2513 7971 5063 ...

correct output
964692694

user output
-4141917025116900187

Test 7

Group: 3

Verdict:

input
1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1000000

user output
(empty)

Test 8

Group: 3

Verdict:

input
1000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
229147081

user output
(empty)

Test 9

Group: 3

Verdict:

input
1000
520283 805991 492643 75254 527...

correct output
951147313

user output
(empty)