Submission #1083033

# Submission time Handle Problem Language Result Execution time Memory
1083033 2024-09-02T10:30:59 Z Seungni September (APIO24_september) C++17
45 / 100
183 ms 26696 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
//#include "september.h"

#include <vector>

int n;
vector<int> tree[100005];
vector<pii> graph[100005];
int dp[100005];

void init() {
    for (int i = 0; i < n; i++) tree[i].clear(), graph[i].clear();
    return;
}

void DFS(int node) {
    for (int next: tree[node]) {
        DFS(next);
        dp[node] = max(dp[node], dp[next]);
    }
}

void make_graph(vector<int> &arr) {
    
    for (int i = 0; i < n - 1; i++) graph[i].clear();
    for (int i = 0; i < n - 2; i++) graph[i].push_back({i + 1, 1});
    for (int i = 1; i < n - 1; i++) graph[i].push_back({i - 1, 0});
    
    vector<int> pos(n + 1);
    for (int i = 0; i < arr.size(); i++) pos[arr[i]] = i;
    
    for (int i = 1; i < n; i++) dp[i] = pos[i];
    
    DFS(0);
    
    for (int i = 1; i < n; i++) {
        graph[pos[i]].push_back({dp[i], 0});
    }
}

void Dijkstra(int start, vector<int> &dist) {
    fill(dist.begin(), dist.end(), 1e9);
    dist[start] = 1;
    priority_queue<pii, vector<pii>, greater<>> pq;
    pq.push({1, start});
    
    while (pq.size()) {
        pii t = pq.top();
        pq.pop();
        int now = t.second, v = t.first;
        if (dist[now] < v) continue;
        for (auto &[next, cost]: graph[now]) {
            if (dist[next] > v + cost) {
                dist[next] = v + cost;
                pq.push({v + cost, next});
            }
        }
    }
}

int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
    n = N;
    init();
    
    for (int i = 1; i < F.size(); i++) tree[F[i]].push_back(i);
    
    vector<int> dist[5];
    for (int i = 0; i < S.size(); i++) {
        dist[i].resize(N + 5);
        make_graph(S[i]);
        Dijkstra(0, dist[i]);
    }
    
    vector<int> ans(N + 5, 1e9);
    
    vector<int> p(N + 5);
    for (int i = 0; i < N - 1; i++) p[S[0][i]] = dist[0][i];
    
    for (int i = 0; i < S.size(); i++) {
        vector<int> now(N + 5);
        int m = 1e9;
        for (int j = N - 2; j >= 0; j--) now[j] = min(min(dist[i][j], p[S[i][j]]), m), m = min(m, now[j]);
        int v = 1;
        p[S[i][0]] = v;
        for (int j = 1; j < N - 1; j++) {
            if (now[j] != now[j - 1]) v++;
            p[S[i][j]] = v;
        }
    }
    
    int ret = 0;
    for (int i = 1; i < N; i++) ret = max(ret, p[i]);
    
    return ret;
}

Compilation message

september.cpp: In function 'void make_graph(std::vector<int>&)':
september.cpp:34:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i = 0; i < arr.size(); i++) pos[arr[i]] = i;
      |                     ~~^~~~~~~~~~~~
september.cpp: In function 'int solve(int, int, std::vector<int>, std::vector<std::vector<int> >)':
september.cpp:69:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for (int i = 1; i < F.size(); i++) tree[F[i]].push_back(i);
      |                     ~~^~~~~~~~~~
september.cpp:72:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for (int i = 0; i < S.size(); i++) {
      |                     ~~^~~~~~~~~~
september.cpp:83:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for (int i = 0; i < S.size(); i++) {
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 5112 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 5112 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Incorrect 3 ms 4956 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 2 ms 5208 KB Output is correct
3 Correct 3 ms 5260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 5112 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 2 ms 5208 KB Output is correct
10 Correct 3 ms 5260 KB Output is correct
11 Correct 2 ms 5172 KB Output is correct
12 Correct 3 ms 5208 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 3 ms 5212 KB Output is correct
15 Correct 2 ms 5464 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 2 ms 5208 KB Output is correct
3 Correct 3 ms 5260 KB Output is correct
4 Incorrect 4 ms 5212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 5112 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Incorrect 3 ms 4956 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 2 ms 5208 KB Output is correct
3 Correct 3 ms 5260 KB Output is correct
4 Correct 158 ms 26440 KB Output is correct
5 Correct 150 ms 26696 KB Output is correct
6 Correct 145 ms 26616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 5112 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 5212 KB Output is correct
9 Correct 2 ms 5208 KB Output is correct
10 Correct 3 ms 5260 KB Output is correct
11 Correct 2 ms 5172 KB Output is correct
12 Correct 3 ms 5208 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 3 ms 5212 KB Output is correct
15 Correct 2 ms 5464 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5212 KB Output is correct
18 Correct 158 ms 26440 KB Output is correct
19 Correct 150 ms 26696 KB Output is correct
20 Correct 145 ms 26616 KB Output is correct
21 Correct 183 ms 22108 KB Output is correct
22 Correct 169 ms 22100 KB Output is correct
23 Correct 162 ms 22612 KB Output is correct
24 Correct 164 ms 22620 KB Output is correct
25 Correct 165 ms 21844 KB Output is correct
26 Correct 161 ms 22360 KB Output is correct
27 Correct 168 ms 23068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5212 KB Output is correct
2 Correct 2 ms 5208 KB Output is correct
3 Correct 3 ms 5260 KB Output is correct
4 Incorrect 4 ms 5212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 5112 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 3 ms 4956 KB Output is correct
9 Incorrect 3 ms 4956 KB Output isn't correct
10 Halted 0 ms 0 KB -