#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(){
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<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:210: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]
210 | for (int i=0; i<moves.size();i++){
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
2380 KB |
Output is correct |
2 |
Correct |
25 ms |
2496 KB |
Output is correct |
3 |
Execution timed out |
2078 ms |
131704 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
136 ms |
5312 KB |
Output is correct |
2 |
Correct |
142 ms |
5316 KB |
Output is correct |
3 |
Correct |
128 ms |
5340 KB |
Output is correct |
4 |
Correct |
127 ms |
5312 KB |
Output is correct |
5 |
Correct |
131 ms |
5324 KB |
Output is correct |
6 |
Correct |
136 ms |
5228 KB |
Output is correct |
7 |
Correct |
159 ms |
5276 KB |
Output is correct |
8 |
Correct |
134 ms |
5472 KB |
Output is correct |
9 |
Correct |
135 ms |
5300 KB |
Output is correct |
10 |
Correct |
132 ms |
5336 KB |
Output is correct |
11 |
Correct |
118 ms |
5372 KB |
Output is correct |
12 |
Correct |
126 ms |
5420 KB |
Output is correct |
13 |
Correct |
124 ms |
5224 KB |
Output is correct |
14 |
Correct |
130 ms |
5316 KB |
Output is correct |
15 |
Correct |
106 ms |
5252 KB |
Output is correct |
16 |
Correct |
118 ms |
5328 KB |
Output is correct |
17 |
Correct |
121 ms |
5324 KB |
Output is correct |
18 |
Correct |
120 ms |
5256 KB |
Output is correct |
19 |
Correct |
122 ms |
5336 KB |
Output is correct |
20 |
Correct |
123 ms |
5232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
2380 KB |
Output is correct |
2 |
Correct |
25 ms |
2496 KB |
Output is correct |
3 |
Execution timed out |
2078 ms |
131704 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
2380 KB |
Output is correct |
2 |
Correct |
25 ms |
2496 KB |
Output is correct |
3 |
Execution timed out |
2078 ms |
131704 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |