Submission #697363

# Submission time Handle Problem Language Result Execution time Memory
697363 2023-02-09T12:51:59 Z micjan Group Photo (JOI21_ho_t3) C++14
12 / 100
179 ms 296 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define st first
#define nd second
#define FOR(i,j,k) for(auto i = (j); i<(k); i++)
#define ROF(i,j,k) for(auto i = (k)-1; i>=(j); i--)
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define pb push_back
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);

const int MN = 21;
const int MM = 2e5+10;
const ll inf = 1e18+2;

vi V;
void gen(int mask, int n)
{
	bitset<MN> M = mask;
	int i = 0;
	while(i<n)
	{
		int j = i;
		while(M[j]) j++;
		V.pb(j);
		ROF(k,i,j) V.pb(k);
		i = j+1;
	}
}

int c(int n, vi C)//koszt uzyskania V z C
{
	int rep = 0;
	FOR(i,0,n)
	{
		int k = V[i];
		int p = i;
		while(C[p] != k) p++;
		while(p>i)
		{
			swap(C[p],C[p-1]);
			p--;
			rep++;
		}
	}
	return rep;
}


int main()
{
	int n;
	cin>>n;
	vi C(n);
	FOR(i,0,n)
	{
		cin>>C[i];
		C[i]--;
	}
	int ans = 1e9+7;
	FOR(m,0,1<<(n-1))
	{
		V.clear();
		gen(m,n);
		ans = min(c(n,C),ans);
	}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 224 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 224 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 37 ms 212 KB Output is correct
12 Correct 67 ms 276 KB Output is correct
13 Correct 75 ms 280 KB Output is correct
14 Correct 157 ms 276 KB Output is correct
15 Correct 157 ms 276 KB Output is correct
16 Correct 155 ms 280 KB Output is correct
17 Correct 179 ms 276 KB Output is correct
18 Correct 168 ms 212 KB Output is correct
19 Correct 169 ms 292 KB Output is correct
20 Correct 153 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 224 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 37 ms 212 KB Output is correct
12 Correct 67 ms 276 KB Output is correct
13 Correct 75 ms 280 KB Output is correct
14 Correct 157 ms 276 KB Output is correct
15 Correct 157 ms 276 KB Output is correct
16 Correct 155 ms 280 KB Output is correct
17 Correct 179 ms 276 KB Output is correct
18 Correct 168 ms 212 KB Output is correct
19 Correct 169 ms 292 KB Output is correct
20 Correct 153 ms 296 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 224 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 37 ms 212 KB Output is correct
12 Correct 67 ms 276 KB Output is correct
13 Correct 75 ms 280 KB Output is correct
14 Correct 157 ms 276 KB Output is correct
15 Correct 157 ms 276 KB Output is correct
16 Correct 155 ms 280 KB Output is correct
17 Correct 179 ms 276 KB Output is correct
18 Correct 168 ms 212 KB Output is correct
19 Correct 169 ms 292 KB Output is correct
20 Correct 153 ms 296 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 224 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 37 ms 212 KB Output is correct
12 Correct 67 ms 276 KB Output is correct
13 Correct 75 ms 280 KB Output is correct
14 Correct 157 ms 276 KB Output is correct
15 Correct 157 ms 276 KB Output is correct
16 Correct 155 ms 280 KB Output is correct
17 Correct 179 ms 276 KB Output is correct
18 Correct 168 ms 212 KB Output is correct
19 Correct 169 ms 292 KB Output is correct
20 Correct 153 ms 296 KB Output is correct
21 Incorrect 1 ms 212 KB Output isn't correct
22 Halted 0 ms 0 KB -