Submission #1369542

#TimeUsernameProblemLanguageResultExecution timeMemory
1369542AndreyBOI Acronym (BOI25_boi)C++17
100 / 100
60 ms25620 KiB
#include<bits/stdc++.h>
using namespace std;

int haha[2001][2001];
vector<int> idk[2001];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        for(int j = i; j <= n; j++) {
            cin >> haha[i][j];
        }
    }
    idk[1].push_back(1);
    for(int i = 2; i <= n; i++) {
        if(haha[1][i] == haha[1][i-1]) {
            idk[i] = idk[i-1];
            continue;
        }
        int br = haha[1][i];
        int z = idk[i-1][0];
        if(haha[z+1][i] == br-1 && haha[z][i] == br) {
            idk[i] = idk[i-1];
            idk[i].push_back(i);
            continue;
        }
        vector<int> wut(i+1,-1);
        for(int v: idk[i-1]) {
            wut[v] = 1;
        }
        wut[i] = 2;
        int p = 0;
        for(int j = i-1; j >= 1; j--) {
            if(wut[idk[j][0]] == -1) {
                p = j;
                break;
            }
        }
        if(p != 0) {
            int y = idk[p][0],c1 = 3,c2 = 2;
            if(haha[y][i] == br && haha[y+1][i] == br-1) {
                c1 = 2;
                c2 = 3;
            }
            for(int v: idk[p]) {
                wut[v] = c1;
            }
            for(int j = 1; j <= p; j++) {
                if(wut[j] == -1) {
                    wut[j] = c2;
                }
            }
        }
        int br2 = 1,br3 = 0;
        for(int j = i-1; j > p; j--) {
            if(wut[j] == 1) {
                continue;
            }
            if(br2 == br3) {
                if(haha[j][i-1] == br2) {
                    wut[j] = 2;
                    br2++;
                }
                else {
                    wut[j] = 3;
                    br3++;
                }
            }
            else {
                if(haha[j][i] == max(br2,br3)) {
                    if(br2 < br3) {
                        br2++;
                        wut[j] = 2;
                    }
                    else {
                        br3++;
                        wut[j] = 3;
                    }
                }
                else {
                    if(br2 < br3) {
                        br3++;
                        wut[j] = 3;
                    }
                    else {
                        br2++;
                        wut[j] = 2;
                    }
                }
            }
        }
        for(int j = 1; j <= i; j++) {
            if(wut[j] == 2) {
                idk[i].push_back(j);
            }
        }
    }
    for(int v: idk[n]) {
        cout << v << " ";
    }
    return 0;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...