CSES - Datatähti 2023 alku - Results
Submission details
Task:Ruudukko
Sender:Mariia
Submission time:2022-11-13 19:34:24 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:46:13: error: redeclaration of 'int jnow'
   46 |         int jnow = jj[jnow].size();
      |             ^~~~
input/code.cpp:35:13: note: 'int jnow' previously declared here
   35 |         int jnow = now % n;
      |             ^~~~
input/code.cpp:47:29: error: 'jsize' was not declared in this scope; did you mean 'isize'?
   47 |         for (int p = 0; p < jsize; p++) {
      |                             ^~~~~
      |                             isize

Code

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int mod = 1e9 + 7;

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

    int n; cin >> n;
    vector<int> t(n * n);
    vector<pair<int, int>> a(n * n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> t[i * n + j];
            a[i * n + j] = {t[i * n + j], i * n + j};
        }
    }
    sort(a.begin(), a.end());

    vector<int> dp(n * n, 0);
    vector<vector<int>> ii(n);
    vector<vector<int>> jj(n);

    int ANS = 0;

    for (int x = 0; x < n * n; x++) {
        int now = a[x].second;
        int inow = now / n;
        int jnow = now % n;

        int isize = ii[inow].size();
        for (int p = 0; p < isize; p++) {
            if (t[now] > t[ii[inow][p]]) {
                dp[now] += dp[ii[inow][p]];
                dp[now] %= mod;
            }
        }
        ii[inow].push_back(now);

        int jnow = jj[jnow].size();
        for (int p = 0; p < jsize; p++) {
            if (t[now] > t[jj[jnow][p]]) {
                dp[now] += dp[jj[jnow][p]];
                dp[now] %= mod;
            }
        }
        jj[jnow].push_back(now);

        dp[now] += 1;
        ANS += dp[now];
        ANS %= mod;
    }
    cout << ANS;
}