이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#include "wiring.h"
const int MX=1e5+5;
long long min_total_length(vector<int> r, vector<int> b){
vector<int>v(2e5+5,0);
for(int i=0;i<(int)r.size();i++){
v[r[i]]=1;
}
int say=0,n=(int)r.size() + (int)b.size();
vector<int>tt;
for(int i=0;i<=n;i++){
if(i==0 || v[i]==v[i-1]){
say++;
}
else{
tt.push_back(say);
say=1;
}
}
tt.push_back(say);
long long res=0;
int j=1,i=0;
while(i<n){
if(tt[i]==0){
i++;
continue;
}
if(i==j){
if(i==tt.size()-1){
break;
}
j++;
}
if(j==tt.size()){
}
int tmp=min(tt[i],tt[j]);
res+=(tmp*tmp);
tt[i]-=tmp;
tt[j]-=tmp;
if(tt[i]==0){
i++;
}
if(tt[j]==0){
j++;
}
}
for(int i=0;i<tt.size();i++){
res += (tt[i] * (tt[i]-1) /2);
}
return res;
}
/*int main() {
int n, m;
assert(2 == scanf("%d %d", &n, &m));
vector<int> r(n), b(m);
for(int i = 0; i < n; i++)
assert(1 == scanf("%d", &r[i]));
for(int i = 0; i < m; i++)
assert(1 == scanf("%d", &b[i]));
long long res = min_total_length(r, b);
printf("%lld\n", res);
return 0;
}*/
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:40:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if(i==tt.size()-1){
| ~^~~~~~~~~~~~~
wiring.cpp:45:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if(j==tt.size()){
| ~^~~~~~~~~~~
wiring.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i=0;i<tt.size();i++){
| ~^~~~~~~~~~
# | 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... |