제출 #1285145

#제출 시각아이디문제언어결과실행 시간메모리
1285145baotoan655Rope (JOI17_rope)C++20
100 / 100
438 ms85932 KiB
#include <bits/stdc++.h>
#define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;
const int N = 1e6 + 5;

int D[N][2];
bitset<N> bs;

vector<int> g[N];
int O[N];
int a[N], b[N];

int n, m;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    file("a") else file("task");
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        b[a[i]]++;
    }
    for(int i = 1; i <= m; i++) g[b[i]].emplace_back(i);
    for(int i = n, c = 0; i; i--)
        for(int v : g[i]) O[++c] = v;
    for(int i = 0; i <= n; i++) g[i].clear();
    for(int i = 1; i < n; i++) if(a[i] != a[i + 1]) {
            g[a[i]].emplace_back(i + 1);
            g[a[i + 1]].emplace_back(-i);
        }

    for(int i = 1; i <= m; i++) {
        int ret = 0, dg = 0;
        for(int v : g[i]) {
            D[a[abs(v)]][(0 < v ? v - 1 : -v) & 1]++;
            bs[a[abs(v)]] = true;
            dg++;
        }
        for(int oi = 1, c; oi <= m && oi <= dg + 2; oi++) {
            c = O[oi];
            if(c == i || bs[c]) continue;
            ret = -b[c];
            break;
        }
        for(int v : g[i]) {
            int c = a[abs(v)], t = min(D[c][0], D[c][1]) - b[c];
            if(t < ret) ret = t;
        }
        for(int v : g[i]) {
            D[a[abs(v)]][(0 < v ? v - 1 : -v) & 1] = 0;
            bs[a[abs(v)]] = false;
        }
        cout << ret + n - b[i] << '\n';
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

rope.cpp: In function 'int main()':
rope.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
rope.cpp:18:5: note: in expansion of macro 'file'
   18 |     file("a") else file("task");
      |     ^~~~
rope.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
rope.cpp:18:5: note: in expansion of macro 'file'
   18 |     file("a") else file("task");
      |     ^~~~
rope.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
rope.cpp:18:20: note: in expansion of macro 'file'
   18 |     file("a") else file("task");
      |                    ^~~~
rope.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
rope.cpp:18:20: note: in expansion of macro 'file'
   18 |     file("a") else file("task");
      |                    ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...