#include <bits/stdc++.h>
using namespace std;
#define ll long long
string con(vector<string> s){
string ans ="";
for (int i=0; i<s.size();i++){
ans+= s[i];
}
return ans;
}
vector<string> gen(string s){
vector<string> ans;
if (s.size()==1){
return {"0"};
}
else if (s.size() ==2){
return {"01","10"};
}
else if (s.size() ==3){
return {"012","021","120","102","201","210"};
}
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(con(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(con(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(con(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(con(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(con(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(con(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(con(t));
}
}
return ans;
}
int check(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(){
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<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
Main.cpp: In function 'std::string con(std::vector<std::__cxx11::basic_string<char> >)':
Main.cpp:6:20: 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]
6 | for (int i=0; i<s.size();i++){
| ~^~~~~~~~~
Main.cpp: In function 'std::vector<std::__cxx11::basic_string<char> > gen(std::string)':
Main.cpp:23:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:24:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:25:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int k =2;k<s.size(); k++){
| ~^~~~~~~~~
Main.cpp:37:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:38:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:39:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:40:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int l =3;l<s.size(); l++){
| ~^~~~~~~~~
Main.cpp:54:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:55:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:56:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:57:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:58:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int m =4;m<s.size(); m++){
| ~^~~~~~~~~
Main.cpp:74:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:75:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:76:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:77:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:78:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:79:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for (int n =5;n<s.size(); n++){
| ~^~~~~~~~~
Main.cpp:97:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for (int i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:98:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:99:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:100:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:101:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:102:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for (int n =5;n<s.size(); n++)
| ~^~~~~~~~~
Main.cpp:103:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | 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 i =0;i<s.size(); i++)
| ~^~~~~~~~~
Main.cpp:124:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for (int j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:125:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
125 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:126:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
126 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:127:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
127 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:128:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
128 | for (int n =5;n<s.size(); n++)
| ~^~~~~~~~~
Main.cpp:129:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
129 | for (int o =6;o<s.size(); o++)
| ~^~~~~~~~~
Main.cpp:130:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
130 | for (int p =7;p<s.size(); p++){
| ~^~~~~~~~~
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 i =0;i<s.size(); i++)
| ~^~~~~~~~~
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 j =1;j<s.size(); j++)
| ~^~~~~~~~~
Main.cpp:154:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
154 | for (int k =2;k<s.size(); k++)
| ~^~~~~~~~~
Main.cpp:155:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
155 | for (int l =3;l<s.size(); l++)
| ~^~~~~~~~~
Main.cpp:156:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
156 | for (int m =4;m<s.size(); m++)
| ~^~~~~~~~~
Main.cpp:157:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
157 | for (int n =5;n<s.size(); n++)
| ~^~~~~~~~~
Main.cpp:158:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
158 | for (int o =6;o<s.size(); o++)
| ~^~~~~~~~~
Main.cpp:159:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
159 | for (int p =7;p<s.size(); p++)
| ~^~~~~~~~~
Main.cpp:160:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
160 | for (int q =8;q<s.size(); q++){
| ~^~~~~~~~~
Main.cpp: In function 'int check(std::string, std::vector<int>, std::vector<int>)':
Main.cpp:187:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
187 | for (int i=0;i<action.size();i++){
| ~^~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:209:24: 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]
209 | for (int i=0; i<moves.size();i++){
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2376 KB |
Output is correct |
2 |
Correct |
26 ms |
2380 KB |
Output is correct |
3 |
Execution timed out |
2071 ms |
131740 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
516 ms |
5908 KB |
Output is correct |
2 |
Correct |
435 ms |
6136 KB |
Output is correct |
3 |
Correct |
433 ms |
6348 KB |
Output is correct |
4 |
Correct |
411 ms |
6264 KB |
Output is correct |
5 |
Correct |
462 ms |
5832 KB |
Output is correct |
6 |
Correct |
520 ms |
5664 KB |
Output is correct |
7 |
Correct |
358 ms |
6348 KB |
Output is correct |
8 |
Correct |
385 ms |
5988 KB |
Output is correct |
9 |
Correct |
368 ms |
5832 KB |
Output is correct |
10 |
Correct |
390 ms |
5720 KB |
Output is correct |
11 |
Correct |
332 ms |
5664 KB |
Output is correct |
12 |
Correct |
361 ms |
6004 KB |
Output is correct |
13 |
Correct |
337 ms |
5724 KB |
Output is correct |
14 |
Correct |
336 ms |
5892 KB |
Output is correct |
15 |
Correct |
369 ms |
6144 KB |
Output is correct |
16 |
Correct |
374 ms |
6068 KB |
Output is correct |
17 |
Correct |
356 ms |
5736 KB |
Output is correct |
18 |
Correct |
370 ms |
5872 KB |
Output is correct |
19 |
Correct |
376 ms |
5996 KB |
Output is correct |
20 |
Correct |
356 ms |
6256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2376 KB |
Output is correct |
2 |
Correct |
26 ms |
2380 KB |
Output is correct |
3 |
Execution timed out |
2071 ms |
131740 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
2376 KB |
Output is correct |
2 |
Correct |
26 ms |
2380 KB |
Output is correct |
3 |
Execution timed out |
2071 ms |
131740 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |