CSES - Datatähti 2023 alku - Results
Submission details
Task:Ruudukko
Sender:Septicuss
Submission time:2022-11-13 20:46:37 +0200
Language:C++17
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED28
#2ACCEPTED33
#3ACCEPTED39
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.00 s1, 2, 3details
#3ACCEPTED0.00 s1, 2, 3details
#4ACCEPTED0.01 s2, 3details
#5ACCEPTED0.01 s2, 3details
#6ACCEPTED0.01 s2, 3details
#7ACCEPTED0.21 s3details
#8ACCEPTED0.29 s3details
#9ACCEPTED0.36 s3details

Compiler report

input/code.cpp: In function 'void printdlin(std::vector<long long int>&)':
input/code.cpp:28:15: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   28 |     printf ("%d", v.empty() ? 0 : v.back());
      |              ~^   ~~~~~~~~~~~~~~~~~~~~~~~~
      |               |             |
      |               int           long long int
      |              %lld
input/code.cpp:30:21: warning: format '%d' expects argument of type 'int', but argument 2 has type '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} [-Wformat=]
   30 |         printf ("%04d", v[i]);
      |                  ~~~^
      |                     |
      |                     int
      |                  %04lld
input/code.cpp: In function 'void sum(std::vector<long long int>&, std::vector<long long int>&)':
input/code.cpp:36:23: warning: comparison of integer expressions of different signedness: 'long long...

Code

#include "bits/stdc++.h"
#define int long long

using namespace std;

#define f first
#define s second
#define mp make_pair
#define pb push_back

const int inf = 1e9, mod = 1e9 + 7, dig = 4, base = 1e4;

vector<int> f, s, ans;

void getdlin(vector<int>& arr){
    string fs;
    cin >> fs;
    for(int i = (int)fs.size(); i > 0; i -= dig){
        if(i < dig){
            arr.pb(atoi(fs.substr(0, i).c_str()));
        }else{
            arr.pb(atoi(fs.substr(i - dig, dig).c_str()));
        }
    }
}

void printdlin(vector<int>& v){
    printf ("%d", v.empty() ? 0 : v.back());
    for (int i = (int)v.size() - 2; i >= 0; --i){
        printf ("%04d", v[i]);
    }
}

void sum(vector<int>& f, vector<int>& s){
    int carry = 0;
    for (int i = 0; i < max(f.size(), s.size()) || carry; ++i) {
        if (i == f.size()){
             f.push_back (0);
        }
        f[i] += carry + (i < s.size() ? s[i] : 0);
        carry = 0;
        if (f[i] >= base){
            f[i] -= base;
            ++carry;
        }
    }
}

bool comp(vector<int>& f, vector<int>& s){
    if(f.size() != s.size()){
        return f.size() > s.size();
    }
    for(int i = f.size() - 1; i >= 0; --i){
        if(f[i] != s[i]){
            return f[i] > s[i];
        }
    }
    return true;
}


int cmp(pair<int, pair<int,int>> a, pair<int, pair<int,int>> b) {
  return a.first < b.first;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, x;
    cin >> n;
    vector<pair<int, pair<int, int>>> arr;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> x;
            arr.push_back({x, {i + 1, j + 1}});
        }
    }

    sort(arr.begin(), arr.end(), cmp);

    vector<int> a(n + 1), b(n + 1), res(n * n);

    for (int i = 0; i < n * n; 1) {
        int j = i;
        while (j < n * n && arr[j].first == arr[i].first) {
            ++j;
        }
        for (int x = i; x < j; ++x) {
            res[x] = a[arr[x].second.first] + b[arr[x].second.second] + 1;
        }

        for (int x = i; x < j; ++x) {
            a[arr[x].second.first] = (a[arr[x].second.first] + res[x]) % mod;
            b[arr[x].second.second] = (b[arr[x].second.second] + res[x]) % mod;
        }

        i = j;
    }

    int ans = 0;
    for (int i = 0; i < n * n; ++i)
        ans = (ans + res[i]) % mod;

    cout << ans << '\n';    
}

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: ACCEPTED

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

correct output
187458477

user output
187458477

Test 6

Group: 2, 3

Verdict: ACCEPTED

input
100
2995 8734 1018 2513 7971 5063 ...

correct output
964692694

user output
964692694

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: ACCEPTED

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

correct output
229147081

user output
229147081

Test 9

Group: 3

Verdict: ACCEPTED

input
1000
520283 805991 492643 75254 527...

correct output
951147313

user output
951147313