답안 #752685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
752685 2023-06-03T12:23:27 Z benjaminkleyn 벽 칠하기 (APIO20_paint) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#include "paint.h"
using namespace std;

struct section
{
    // used to store a segment of the wall which i know can be painted nicely.
    int x, y, cnt;
    // we can do this for 0 <= l < cnt, instead of just M.
};

bool operator<(const section &X, const section &Y)
{
    return X.y + X.cnt < Y.y + Y.cnt;
}

int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B)
{
    vector<set<int>> b(M);
    for (int i = 0; i < M; i++)
        b[i] = set<int>(B[i].begin(), B[i].end());

    vector<section> sections1;
    for (int offset = 0; offset < M; offset++)
    {
        int cnt = 0;
        for (int i = 0; i < N; i++)
        {
            if (b[(i + offset) % M].find(C[i]) == b[(i + offset) % M].end())
            {
                if (cnt >= M)
                    sections1.push_back({(i - cnt + offset) % M, i - cnt, cnt});
                cnt = 0;
            }
            else
                cnt++;
        }
        if (cnt >= M)
            sections1.push_back({(N - cnt + offset) % M, N - cnt, cnt});
    }

    sort(sections1.begin(), sections1.end(), [] (const section &X, const section &Y) { return X.y < Y.y; });

    vector<bool> done(N, false);
    int ans = 0;
    set<section> sections;
    int r = 0;
    for (int i = 0; i < N; i++)
    {
        while (r < sections1.size() && sections1[r].y == i)
            sections.insert(sections1[r++]);

        if (!done[i])
        {
            if (sections.size() == 0)
                return 0;
            auto [x, y, cnt] = *sections.rbegin();
            ans++;
            for (int j = i; j < N && j < y + cnt && j < i + M; j++)
                done[j] = true;
        }

        while (sections.begin()->y + sections.begin()->cnt - 1 == i)
            sections.erase(sections.begin());
    }
    
    return ans;
}

Compilation message

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<section>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         while (r < sections1.size() && sections1[r].y == i)
      |                ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -