CSES - Datatähti 2023 alku - Results
Submission details
Task:Ruudukko
Sender:Kemm1706
Submission time:2024-01-11 18:53:26 +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
#7ACCEPTED0.23 s3details
#8--3details
#9--3details

Compiler report

input/code.cpp: In function 'bool sosanh(item, item)':
input/code.cpp:14:7: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   14 |     if(a.val == b.val)
      |       ^

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <ll> vl;
typedef vector <vl> vvl;

struct item
{
    ll val, x, y;
};

bool sosanh(item a, item b)
{
    if(a.val == b.val)
        if(a.x == b.x)
            return a.y < b.y;
        else
            return a.x < b.x;
    return a.val < b.val;
}

void out(vl a)
{
    for(auto x : a)
        cerr << x << " ";
    cerr << "\n";
}

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

    ll n, m, i, j, k = 0, z = 0;
    cin >> n;
    m = n * n;
    vector <item> a(m);
    vvl ans(n, vl(n, 0));
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++)
        {
            cin >> a[k].val;
            a[k].x = i;
            a[k].y = j;
            k++;
        }
    sort(a.begin(), a.end(), sosanh);
    vvl sx(2, vl(n, 0)), sy(2, vl(n, 0));
    i = j = 0;
    while(i < m)
    {
        while(j < m && a[j].val == a[i].val)
        {
            ans[a[j].x][a[j].y] += sx[0][a[j].x] + sy[0][a[j].y] + 1;
            sx[1][a[j].x] += ans[a[j].x][a[j].y];
            sy[1][a[j].y] += ans[a[j].x][a[j].y];
            j++;
        }
        for(k = 0; k < n; k++)
        {
            sx[0][k] += sx[1][k];
            sx[1][k] = 0;
            sy[0][k] += sy[1][k];
            sy[1][k] = 0;
        }
        //out(sx[0]); out(sy[0]);
        //cerr << i << " " << j << "\n";
        i = j;
    }
    for(auto d : ans)
        for(auto t : d)
            z += t;
    cout << z;
    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: ACCEPTED

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

correct output
1000000

user output
1000000

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)