제출 #61754

#제출 시각아이디문제언어결과실행 시간메모리
61754gusfringRope (JOI17_rope)C++14
45 / 100
55 ms26780 KiB
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> ii;
const int N = 1000005;
 
int n, m, cnt[N];
int a[N], res[N];
int val[N];
vector<int> p[N];
 
int main() {
	scanf("%d %d", &n, &m);
	if (m == 1 || m > 10){ puts("0"); return 0; }
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]); cnt[a[i]]++, p[a[i]].push_back(i);
	}
	set<ii> s;
	for (int i = 1; i <= m; ++i) s.insert(ii(cnt[i], i));
	for (int i = 1; i <= m; ++i) {
		res[i] = 1e9;
		for (int j = 0; j < 2; ++j) {
			vector<int> go;
			int sum = 0;
			for (int k = 0; k < p[i].size(); ++k) {
				if (p[i][k] % 2 == j) {
					int cur = a[p[i][k] - 1];
					if (p[i][k] > 1 && cur != i) {
						if (++val[cur] == 1) go.push_back(cur);
					}
				}
				else {
					int cur = a[p[i][k] + 1];
					if (p[i][k] < n && cur != i) {
						if (++val[cur] == 1) go.push_back(cur);
					}
				}
			}
			for (int k = 0; k < go.size(); ++k) {
				s.erase(s.find(ii(cnt[go[k]], go[k])));
				s.insert(ii(cnt[go[k]] - val[go[k]], go[k]));
			}
			s.erase(s.find(ii(cnt[i], i)));
			res[i] = min(res[i], n - ((*(--s.end())).first + cnt[i]));
			for (int k = 0; k < go.size(); ++k) {
				s.erase(s.find(ii(cnt[go[k]] - val[go[k]], go[k])));
				s.insert(ii(cnt[go[k]], go[k]));				
			}
			s.insert(ii(cnt[i], i));
			for (int k = 0; k < go.size(); ++k) val[go[k]] = 0;
		}
		printf("%d\n", res[i]);
	}
}

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

rope.cpp: In function 'int main()':
rope.cpp:25:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < p[i].size(); ++k) {
                    ~~^~~~~~~~~~~~~
rope.cpp:39:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < go.size(); ++k) {
                    ~~^~~~~~~~~~~
rope.cpp:45:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < go.size(); ++k) {
                    ~~^~~~~~~~~~~
rope.cpp:50:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < go.size(); ++k) val[go[k]] = 0;
                    ~~^~~~~~~~~~~
rope.cpp:24:8: warning: unused variable 'sum' [-Wunused-variable]
    int sum = 0;
        ^~~
rope.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
rope.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]); cnt[a[i]]++, p[a[i]].push_back(i);
   ~~~~~^~~~~~~~~~~~~
#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...