이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000001;
vector<int> cc[maxn];
set<pair<int,int>> ck;
int a[maxn];
int u[maxn];
int ans[maxn];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin >> n >> m;
for(int j = 0;j < n;++j)
{
cin >> a[j];
a[j]--;
cc[a[j]].push_back(j);
}
for(int j = 0;j < m;++j)
{
u[j] = cc[j].size();
ck.insert({-u[j],j});
ans[j] = n+1;
}
for(int j = 0;j < m;++j)
{
int op = u[j];
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 1)
break;
int pr = a[cc[j][k]^1];
ck.erase({-u[pr],pr});
u[pr]--;
ck.insert({-u[pr],pr});
}
ck.erase({-u[j],j});
ans[j] = min(ans[j],(ck.size() == 0 ? 0 : n-op+(*ck.begin()).first));
ck.insert({-u[j],j});
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 1)
break;
int pr = a[cc[j][k]^1];
ck.erase({-u[pr],pr});
u[pr]++;
ck.insert({-u[pr],pr});
}
}
for(int j = 0;j < m;++j)
{
int op = u[j];
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 0)
break;
if(cc[j][k] == 0)
continue;
int pr = a[((cc[j][k]-1)^1)+1];
ck.erase({-u[pr],pr});
u[pr]--;
ck.insert({-u[pr],pr});
}
ck.erase({-u[j],j});
ans[j] = min(ans[j],(ck.size() == 0 ? 0 : n-op+(*ck.begin()).first));
ck.insert({-u[j],j});
for(int k = 0;k < cc[j].size();++k)
{
if(cc[j][k] == n-1 && n%2 == 0)
break;
if(cc[j][k] == 0)
continue;
int pr = a[((cc[j][k]-1)^1)+1];
ck.erase({-u[pr],pr});
u[pr]++;
ck.insert({-u[pr],pr});
}
cout << ans[j] << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
rope.cpp: In function 'int main()':
rope.cpp:34:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int k = 0;k < cc[j].size();++k)
| ~~^~~~~~~~~~~~~~
rope.cpp:46:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int k = 0;k < cc[j].size();++k)
| ~~^~~~~~~~~~~~~~
rope.cpp:59:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int k = 0;k < cc[j].size();++k)
| ~~^~~~~~~~~~~~~~
rope.cpp:73:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for(int k = 0;k < cc[j].size();++k)
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |