This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<string>> gen(string s){
vector<vector<string>> ans;
if (s.size()==1){
return {{"0"}};
}
else if (s.size() ==2){
return {{"0","1"},{"1","0"}};
}
else if (s.size() ==3){
return {{"0","1","2"},{"0","2","1"},{"1","2","0"},{"1","0","2"},{"2","0","1"},{"2","1","0"}};
}
else if (s.size() ==4){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++){
vector<string> t = {"0","1","2","3"};
string a= t[i];
t[i] = t[0]; t[0] = a;
string b= t[j];
t[j] = t[1]; t[1] = b;
string c= t[k];
t[k] = t[2]; t[2] = c;
ans.push_back(t);
}
}
else if (s.size() ==5){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++){
vector<string> t = {"0","1","2","3","4"};
string a= t[i];
t[i] = t[0]; t[0] = a;
string b= t[j];
t[j] = t[1]; t[1] = b;
string c= t[k];
t[k] = t[2]; t[2] = c;
string d= t[l];
t[l]= t[3]; t[3] = d;
ans.push_back(t);
}
}
else if (s.size() ==6){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++)
for (int m =4;m<s.size(); m++){
vector<string> t = {"0","1","2","3","4","5"};
string a= t[i];
t[i] = t[0]; t[0] = a;
string b= t[j];
t[j] = t[1]; t[1] = b;
string c= t[k];
t[k] = t[2]; t[2] = c;
string d= t[l];
t[l]= t[3]; t[3] = d;
string e = t[m];
t[m] = t[4]; t[4] = e;
ans.push_back(t);
}
}
else if (s.size() ==7){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++)
for (int m =4;m<s.size(); m++)
for (int n =5;n<s.size(); n++){
vector<string> t = {"0","1","2","3","4","5","6"};
string a= t[i];
t[i] = t[0]; t[0] = a;
string b= t[j];
t[j] = t[1]; t[1] = b;
string c= t[k];
t[k] = t[2]; t[2] = c;
string d= t[l];
t[l]= t[3]; t[3] = d;
string e = t[m];
t[m] = t[4]; t[4] = e;
string f = t[n];
t[n] = t[5]; t[5] = f;
ans.push_back(t);
}
}
else if (s.size() ==8){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++)
for (int m =4;m<s.size(); m++)
for (int n =5;n<s.size(); n++)
for (int o =6;o<s.size(); o++){
vector<string> t = {"0","1","2","3","4","5","6","7"};
string a= t[i];
t[i] = t[0]; t[0] = a;
string b= t[j];
t[j] = t[1]; t[1] = b;
string c= t[k];
t[k] = t[2]; t[2] = c;
string d= t[l];
t[l]= t[3]; t[3] = d;
string e = t[m];
t[m] = t[4]; t[4] = e;
string f = t[n];
t[n] = t[5]; t[5] = f;
string g = t[o];
t[o] = t[6]; t[6] = g;
ans.push_back(t);
}
}
else if (s.size() ==9){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++)
for (int m =4;m<s.size(); m++)
for (int n =5;n<s.size(); n++)
for (int o =6;o<s.size(); o++)
for (int p =7;p<s.size(); p++){
vector<string> t = {"0","1","2","3","4","5","6","7","8"};
string a= t[i];
t[i] = t[0]; t[0] = a;
string b= t[j];
t[j] = t[1]; t[1] = b;
string c= t[k];
t[k] = t[2]; t[2] = c;
string d= t[l];
t[l]= t[3]; t[3] = d;
string e = t[m];
t[m] = t[4]; t[4] = e;
string f = t[n];
t[n] = t[5]; t[5] = f;
string g = t[o];
t[o] = t[6]; t[6] = g;
string h = t[p];
t[p] = t[7]; t[7] = h;
ans.push_back(t);
}
}
else if (s.size() ==10){
for (int i =0;i<s.size(); i++)
for (int j =1;j<s.size(); j++)
for (int k =2;k<s.size(); k++)
for (int l =3;l<s.size(); l++)
for (int m =4;m<s.size(); m++)
for (int n =5;n<s.size(); n++)
for (int o =6;o<s.size(); o++)
for (int p =7;p<s.size(); p++)
for (int q =8;q<s.size(); q++){
vector<string> t = {"0","1","2","3","4","5","6","7","8","9"};
string a= t[i];
t[i] = t[0]; t[0] = a;
string b= t[j];
t[j] = t[1]; t[1] = b;
string c= t[k];
t[k] = t[2]; t[2] = c;
string d= t[l];
t[l]= t[3]; t[3] = d;
string e = t[m];
t[m] = t[4]; t[4] = e;
string f = t[n];
t[n] = t[5]; t[5] = f;
string g = t[o];
t[o] = t[6]; t[6] = g;
string h = t[p];
t[p] = t[7]; t[7] = h;
string z= t[q];
t[q] = t[8]; t[8] = q;
ans.push_back(t);
}
}
return ans;
}
int check(vector<string> action,vector<int> exp, vector<int> levels){
int ans =0, ce= 0;
for (int i=0;i<action.size();i++){
int n = stoi(action[i]+ string());
if (ce<=levels[n]) {ans += 1; ce += exp[n];}
else break;
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
int n,x,ce=0,c=0; cin>>n;
vector<int> exp, levels;
for (int i =0; i<n; i++){
cin>>x;
exp.push_back(x);}
for (int i =0; i<n; i++){
cin>>x;
levels.push_back(x);
}
if (n<=10){
string z="";
int m =0;
for (int i=0; i<n;i++){z+="1";}
vector<vector<string>> moves = gen(z);
for (int i=0; i<moves.size();i++){
m = max(m,check(moves[i],exp,levels));
}
cout<<m;}
else{
sort(exp.begin(),exp.end());
while (ce<=levels[0]){
if (c==n){break;}
ce += exp[c];
c+=1;
}
cout<<c;}
}
Compilation message (stderr)
Main.cpp: In function 'std::vector<std::vector<std::__cxx11::basic_string<char> > > gen(std::string)':
Main.cpp:16:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:17:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:18:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for (int k =2;k<s.size(); k++){
| ~^~~~~~~~~
Main.cpp:30:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:31:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:32:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:33:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int l =3;l<s.size(); l++){
| ~^~~~~~~~~
Main.cpp:47:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:48:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:49:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:50:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:51:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (int m =4;m<s.size(); m++){
| ~^~~~~~~~~
Main.cpp:67:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:68:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:69:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:70:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:71:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:72:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for (int n =5;n<s.size(); n++){
| ~^~~~~~~~~
Main.cpp:90:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:91:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:92:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:93:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:94:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:95:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
95 | for (int n =5;n<s.size(); n++)
| ~^~~~~~~~~
Main.cpp:96:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for (int o =6;o<s.size(); o++){
| ~^~~~~~~~~
Main.cpp:116:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
116 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:117:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:118:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
118 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:119:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
119 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:120:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
120 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:121:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
121 | for (int n =5;n<s.size(); n++)
| ~^~~~~~~~~
Main.cpp:122:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
122 | for (int o =6;o<s.size(); o++)
| ~^~~~~~~~~
Main.cpp:123:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | for (int p =7;p<s.size(); p++){
| ~^~~~~~~~~
Main.cpp:145:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
145 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:146:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
146 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:147:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
147 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:148:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
148 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:149:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
149 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:150:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
150 | for (int n =5;n<s.size(); n++)
| ~^~~~~~~~~
Main.cpp:151:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
151 | for (int o =6;o<s.size(); o++)
| ~^~~~~~~~~
Main.cpp:152:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
152 | for (int p =7;p<s.size(); p++)
| ~^~~~~~~~~
Main.cpp:153:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
153 | for (int q =8;q<s.size(); q++){
| ~^~~~~~~~~
Main.cpp: In function 'int check(std::vector<std::__cxx11::basic_string<char> >, std::vector<int>, std::vector<int>)':
Main.cpp:180:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
180 | for (int i=0;i<action.size();i++){
| ~^~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:203:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
203 | for (int i=0; i<moves.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... |