이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n,a,b,c;
long long mini=1000000000000000000;
string res,resak;
vector<int>v;
map<int,int>mp;
pair<string,long long> solve(vector<int>v2){
string odp="";
long long odpint=0;
for(int i=0;i<n;i++){
int licz[1<<i+1];
for(int j=0;j<1<<i+1;j++)
licz[j]=0;
int wyn=0,wyn2=0;
for(int j=0;j<(int)v2.size();j++){
int smth = v2[j]>>n-i-1;
if(smth%2==0)
wyn+=licz[smth+1];
if(smth%2==1)
wyn2+=licz[smth-1];
licz[smth]++;
}
//cout<<wyn<<" "<<wyn2<<" ";
if(wyn>wyn2){
odp.push_back('1');
}
//cout<<wyn<<" "<<wyn2;
odpint+=min(wyn,wyn2);
for(int j=1;j<n;j++)
odp.push_back('2');
}
// v2={0,1,2,3};
//cout<<" ";
//if(v==v2)
// return {"21",37};
// return {"2137",2137};
return {odp,odpint};
}
int main(){
cin>>n;
a=1<<n;
for(int i=0;i<a;i++)
v.push_back(0);
for(int i=0;i<a;i++){
cin>>b;
v[b]=i;
}
for(int i=0;i<n;i++){
resak.clear();
for(int j=0;j<i;j++)
resak.push_back('2');
pair<string,long long>ak=solve(v);
//cout<<ak.first<<" ";
if(ak.second<mini){
res=resak;
res+=ak.first;
mini=ak.second;
}
// for(int j=0;j<(int)v.size();j++){
//cout<<v[j]<<" ";
// }
for(int j=0;j<(int)v.size();j++){
bool smth=v[j]%2;
v[j]=v[j]>>1;
v[j]+=smth<<n-1;
}
//cout<<"\n";
}
cout<<mini<<"\n"<<res;
}
컴파일 시 표준 에러 (stderr) 메시지
cheerleaders.cpp: In function 'std::pair<std::__cxx11::basic_string<char>, long long int> solve(std::vector<int>)':
cheerleaders.cpp:13:22: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
13 | int licz[1<<i+1];
| ~^~
cheerleaders.cpp:14:27: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
14 | for(int j=0;j<1<<i+1;j++)
| ~^~
cheerleaders.cpp:18:34: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
18 | int smth = v2[j]>>n-i-1;
| ~~~^~
cheerleaders.cpp: In function 'int main()':
cheerleaders.cpp:68:26: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
68 | v[j]+=smth<<n-1;
| ~^~
# | 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... |