Submission #358379

# Submission time Handle Problem Language Result Execution time Memory
358379 2021-01-25T12:01:39 Z Lam_lai_cuoc_doi Xylophone (JOI18_xylophone) C++17
Compilation error
0 ms 0 KB
void solve(int n)
{

    for (int i = 1; i < n; ++i)
    {
        a[i][i + 1] = query(i, i + 1);
        s[a[i][i + 1]].insert({i, i + 1});
    }
    for (int i = 1; i < n - 1; ++i)
    {
        int v = query(i, i + 2);
        if (v == a[i][i + 1] + a[i + 1][i + 2])
        {
            a[i][i + 2] = v;
            s[v].insert({i, i + 2});
        }
        else
        {
            if (v == a[i][i + 1])
            {
                a[i][i + 2] = v - a[i + 1][i + 2];
                s[a[i][i + 2]].insert({i, i + 2});
            }
            else
            {
                a[i][i + 2] = v - a[i][i + 1];
                s[a[i][i + 2]].insert({i, i + 2});
            }
        }
    }
    for (int i = 3; i < n; ++i)
    {
        int sum(0);
        for (int j = 1; j < i - 1; ++j)
            sum += a[j][j + 1];
        for (int j = 1; j <= n - i; ++j)
        {
            sum -= a[j - 1][j];
            sum += a[j + i - 1][j + i];
            int v = query(j, i + j);
            if (v == sum)
            {
                a[j][i + j] = v;
                s[v].insert({j, i + j});
            }
            else
            {
                auto t = s[v].lower_bound({j, 0});
                if (t->first == j)
                {
                    a[j][i + j] = v - a[t->second][j + i];
                    s[a[j][i + j]].insert({j, i + j});
                }
                else if (t->second == j + i)
                {
                    a[j][i + j] = v - a[j][t->first];
                    s[a[j][j + i]].insert({j, j + i});
                }
                else
                {
                    a[j][i + j] = v - min(a[j][t->first] + a[t->second][j + i], a[j][t->second] + a[t->first][j + i]);
                    s[a[j][j + i]].insert({j, j + i});
                }
            }
        }
    }
    int pos;
    for (int i = 1; i <= n; ++i)
        for (int j = i + 1; j <= n; ++j)
            if (a[i][j] == n - 1)
            {
                pos = i;
                goto done;
            }
done:;
    /*for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= n; ++j)
            cout << a[min(i, j)][max(i, j)] << " ";
        cout << "\n";
    }*/
    for (int i = 1; i <= n; ++i)
    {
        if (i == pos)
            answer(i, 1);
        else
            answer(i, 1 + (i < pos ? a[i][pos] : a[pos][i]));
    }
    for (int i = 1; i <= n; ++i)
        s[i].clear();
}

Compilation message

xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:6:9: error: 'a' was not declared in this scope
    6 |         a[i][i + 1] = query(i, i + 1);
      |         ^
xylophone.cpp:6:23: error: 'query' was not declared in this scope
    6 |         a[i][i + 1] = query(i, i + 1);
      |                       ^~~~~
xylophone.cpp:7:9: error: 's' was not declared in this scope
    7 |         s[a[i][i + 1]].insert({i, i + 1});
      |         ^
xylophone.cpp:11:17: error: 'query' was not declared in this scope
   11 |         int v = query(i, i + 2);
      |                 ^~~~~
xylophone.cpp:12:18: error: 'a' was not declared in this scope
   12 |         if (v == a[i][i + 1] + a[i + 1][i + 2])
      |                  ^
xylophone.cpp:15:13: error: 's' was not declared in this scope
   15 |             s[v].insert({i, i + 2});
      |             ^
xylophone.cpp:22:17: error: 's' was not declared in this scope
   22 |                 s[a[i][i + 2]].insert({i, i + 2});
      |                 ^
xylophone.cpp:27:17: error: 's' was not declared in this scope
   27 |                 s[a[i][i + 2]].insert({i, i + 2});
      |                 ^
xylophone.cpp:35:20: error: 'a' was not declared in this scope
   35 |             sum += a[j][j + 1];
      |                    ^
xylophone.cpp:38:20: error: 'a' was not declared in this scope
   38 |             sum -= a[j - 1][j];
      |                    ^
xylophone.cpp:40:21: error: 'query' was not declared in this scope
   40 |             int v = query(j, i + j);
      |                     ^~~~~
xylophone.cpp:44:17: error: 's' was not declared in this scope
   44 |                 s[v].insert({j, i + j});
      |                 ^
xylophone.cpp:48:26: error: 's' was not declared in this scope
   48 |                 auto t = s[v].lower_bound({j, 0});
      |                          ^
xylophone.cpp:61:39: error: 'min' was not declared in this scope
   61 |                     a[j][i + j] = v - min(a[j][t->first] + a[t->second][j + i], a[j][t->second] + a[t->first][j + i]);
      |                                       ^~~
xylophone.cpp:70:17: error: 'a' was not declared in this scope
   70 |             if (a[i][j] == n - 1)
      |                 ^
xylophone.cpp:85:13: error: 'answer' was not declared in this scope
   85 |             answer(i, 1);
      |             ^~~~~~
xylophone.cpp:87:38: error: 'a' was not declared in this scope
   87 |             answer(i, 1 + (i < pos ? a[i][pos] : a[pos][i]));
      |                                      ^
xylophone.cpp:87:13: error: 'answer' was not declared in this scope
   87 |             answer(i, 1 + (i < pos ? a[i][pos] : a[pos][i]));
      |             ^~~~~~
xylophone.cpp:90:9: error: 's' was not declared in this scope
   90 |         s[i].clear();
      |         ^