#include<bits/stdc++.h>
using namespace std;
#define intt long long
#define pb push_back
int main()
{
int n ;
cin>>n;
vector<vector<int>> mat(n , vector<int>(n));
for(int i = 0 ; i < n ; i++)
{
for(int j = 0 ; j < n ; j++)
{
cin>>mat[i][j];
}
}
vector<int> beg ;
for(int i = 0 ; i < n; i++)
beg.pb(i);
vector<vector<int>> states;
queue<vector<int>> q;
q.push(beg);
map<vector<int> , int> vis;
while (!q.empty())
{
auto cur = q.front();
q.pop();
if(vis[cur])
continue;
states.pb(cur);
vis[cur] = 1;
for(int p = 1 ; p < n ; p*=2)
{
for(int i = 0 ; i * p < n ; i+=2)
{
vector<int> new_cur = cur;
for(int j = i * p ; j < (i + 1) * p ; j++)
swap(new_cur[j] , new_cur[j + p]);
if(!vis[new_cur])
q.push(new_cur);
}
}
}
intt ans = LLONG_MAX;
// for(auto state : states)
// {
// cout<<'\n';
// for(auto x : state)
// cout<<x<<" ";
// cout<<'\n';
// }
for(auto state : states)
{
intt cur = 0;
for(int i =0 ; i + 1 < n ; i++)
{
cur+= mat[state[i]][state[i + 1]];
}
ans = min(ans , cur);
}
cout<<ans<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
196 ms |
12296 KB |
Output is correct |
2 |
Correct |
197 ms |
12400 KB |
Output is correct |
3 |
Correct |
209 ms |
12292 KB |
Output is correct |
4 |
Correct |
176 ms |
12292 KB |
Output is correct |
5 |
Correct |
218 ms |
12388 KB |
Output is correct |
6 |
Correct |
192 ms |
12332 KB |
Output is correct |
7 |
Correct |
184 ms |
12296 KB |
Output is correct |
8 |
Correct |
172 ms |
12392 KB |
Output is correct |
9 |
Correct |
174 ms |
12192 KB |
Output is correct |
10 |
Correct |
173 ms |
12296 KB |
Output is correct |
11 |
Correct |
185 ms |
12300 KB |
Output is correct |
12 |
Correct |
178 ms |
12300 KB |
Output is correct |
13 |
Correct |
173 ms |
12296 KB |
Output is correct |
14 |
Correct |
176 ms |
12548 KB |
Output is correct |
15 |
Correct |
173 ms |
12332 KB |
Output is correct |
16 |
Correct |
168 ms |
12296 KB |
Output is correct |
17 |
Correct |
183 ms |
12300 KB |
Output is correct |
18 |
Correct |
169 ms |
12300 KB |
Output is correct |
19 |
Correct |
175 ms |
12340 KB |
Output is correct |
20 |
Correct |
174 ms |
12296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
196 ms |
12296 KB |
Output is correct |
2 |
Correct |
197 ms |
12400 KB |
Output is correct |
3 |
Correct |
209 ms |
12292 KB |
Output is correct |
4 |
Correct |
176 ms |
12292 KB |
Output is correct |
5 |
Correct |
218 ms |
12388 KB |
Output is correct |
6 |
Correct |
192 ms |
12332 KB |
Output is correct |
7 |
Correct |
184 ms |
12296 KB |
Output is correct |
8 |
Correct |
172 ms |
12392 KB |
Output is correct |
9 |
Correct |
174 ms |
12192 KB |
Output is correct |
10 |
Correct |
173 ms |
12296 KB |
Output is correct |
11 |
Correct |
185 ms |
12300 KB |
Output is correct |
12 |
Correct |
178 ms |
12300 KB |
Output is correct |
13 |
Correct |
173 ms |
12296 KB |
Output is correct |
14 |
Correct |
176 ms |
12548 KB |
Output is correct |
15 |
Correct |
173 ms |
12332 KB |
Output is correct |
16 |
Correct |
168 ms |
12296 KB |
Output is correct |
17 |
Correct |
183 ms |
12300 KB |
Output is correct |
18 |
Correct |
169 ms |
12300 KB |
Output is correct |
19 |
Correct |
175 ms |
12340 KB |
Output is correct |
20 |
Correct |
174 ms |
12296 KB |
Output is correct |
21 |
Runtime error |
1157 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
196 ms |
12296 KB |
Output is correct |
2 |
Correct |
197 ms |
12400 KB |
Output is correct |
3 |
Correct |
209 ms |
12292 KB |
Output is correct |
4 |
Correct |
176 ms |
12292 KB |
Output is correct |
5 |
Correct |
218 ms |
12388 KB |
Output is correct |
6 |
Correct |
192 ms |
12332 KB |
Output is correct |
7 |
Correct |
184 ms |
12296 KB |
Output is correct |
8 |
Correct |
172 ms |
12392 KB |
Output is correct |
9 |
Correct |
174 ms |
12192 KB |
Output is correct |
10 |
Correct |
173 ms |
12296 KB |
Output is correct |
11 |
Correct |
185 ms |
12300 KB |
Output is correct |
12 |
Correct |
178 ms |
12300 KB |
Output is correct |
13 |
Correct |
173 ms |
12296 KB |
Output is correct |
14 |
Correct |
176 ms |
12548 KB |
Output is correct |
15 |
Correct |
173 ms |
12332 KB |
Output is correct |
16 |
Correct |
168 ms |
12296 KB |
Output is correct |
17 |
Correct |
183 ms |
12300 KB |
Output is correct |
18 |
Correct |
169 ms |
12300 KB |
Output is correct |
19 |
Correct |
175 ms |
12340 KB |
Output is correct |
20 |
Correct |
174 ms |
12296 KB |
Output is correct |
21 |
Runtime error |
1157 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
196 ms |
12296 KB |
Output is correct |
2 |
Correct |
197 ms |
12400 KB |
Output is correct |
3 |
Correct |
209 ms |
12292 KB |
Output is correct |
4 |
Correct |
176 ms |
12292 KB |
Output is correct |
5 |
Correct |
218 ms |
12388 KB |
Output is correct |
6 |
Correct |
192 ms |
12332 KB |
Output is correct |
7 |
Correct |
184 ms |
12296 KB |
Output is correct |
8 |
Correct |
172 ms |
12392 KB |
Output is correct |
9 |
Correct |
174 ms |
12192 KB |
Output is correct |
10 |
Correct |
173 ms |
12296 KB |
Output is correct |
11 |
Correct |
185 ms |
12300 KB |
Output is correct |
12 |
Correct |
178 ms |
12300 KB |
Output is correct |
13 |
Correct |
173 ms |
12296 KB |
Output is correct |
14 |
Correct |
176 ms |
12548 KB |
Output is correct |
15 |
Correct |
173 ms |
12332 KB |
Output is correct |
16 |
Correct |
168 ms |
12296 KB |
Output is correct |
17 |
Correct |
183 ms |
12300 KB |
Output is correct |
18 |
Correct |
169 ms |
12300 KB |
Output is correct |
19 |
Correct |
175 ms |
12340 KB |
Output is correct |
20 |
Correct |
174 ms |
12296 KB |
Output is correct |
21 |
Runtime error |
1157 ms |
524288 KB |
Execution killed with signal 9 |
22 |
Halted |
0 ms |
0 KB |
- |