답안 #889809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889809 2023-12-20T07:22:12 Z vjudge1 Chorus (JOI23_chorus) C++17
16 / 100
44 ms 2132 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define rnd(l, r) uniform_int_distribution<int>(l, r)(rng)
 
using namespace std;

void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);} 
int pow(int a,int b,int m){int ans=1;while(b){if(b&1){ans=(ans*a)%m;}b>>=1;a=(a*a)%m;}return ans;}
int binpow(int a,int b){int ans=1;while(b){if(b&1){ans=(ans*a);}b>>=1;a=(a*a);}return ans;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int N = 3e5 + 5, inf = 1e9, M = 3e4;

int calc(string a, string b){
	int res = 0;
	vector <int> pos;
	for(int i = 0; i < (int)a.size(); i++){
		if(a[i] == 'A'){
			pos.pb(i);
		}
	}
	for(int i  = (int)b.size() - 1; i >= 0; i--){
		if(b[i] == 'A'){
			res += abs(pos.back() - i);
			pos.pop_back();
		}
	}
	return res;
}
	
main(){
	iostream::sync_with_stdio(false);	
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, k;
    cin >> n >> k;
    n *= 2;
	string s;
	cin >> s;
	set<string> st;
	int ans = inf;
	for(int i = 0; i < ( 1 << n); i++){
		if(__builtin_popcount(i) != n / 2)continue;
		string t = "";
		for(int j = 0; j < n; j++){
			if(i & (1 << j))
				t.pb('B');
			else
				t.pb('A'); 
		}
		string prev = t;
		int r = n - 1, l = n - 1;
		int cnt = 0;
		for(int de = 0; de < k; de++){
			while(r >= 0 && t[r] != 'A'){
				if(t[r] == 'B')
					cnt++;
				r--;
			}
			l = r;
			while(cnt && l >= 0){
				if(t[l] == 'A'){
					cnt--;
					t[l] = '.';
				}
				l--;
			}
		}
		if(l < 0 && cnt == 0){
			st.insert(prev);
			ans = min(ans, calc(s, prev));
			//cout << i << endl;
		}
	}
	cout << ans << endl;
}

/*
 * Before implementing the problem:
	
	Do I understand the problem correctly?
	Which places are tricky? What do I need to remember to implement them correctly?
	Which place is the heaviest by implementation? Can I do it simpler?
	Which place is the slowest? Where do I need to be careful about constant factors and where I can choose slower but simpler implementation?
	----------------------------------
	If not AC:
 
	Did you remember to do everything to handle the tricky places you thought about before?
	Is the solution correct?
	Do I understand the problem correctly?
	----------------------------------
	If you have a test on which the solution gives wrong answer:
 
	Is the solution doing what it was supposed to do?
	Is the problem in the code or in the idea?
*/

Compilation message

chorus.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      | ^~~~
chorus.cpp: In function 'void fp(std::string)':
chorus.cpp:14:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chorus.cpp:14:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 32 ms 848 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 32 ms 708 KB Output is correct
8 Correct 31 ms 344 KB Output is correct
9 Correct 27 ms 452 KB Output is correct
10 Correct 29 ms 444 KB Output is correct
11 Correct 41 ms 2080 KB Output is correct
12 Correct 41 ms 2116 KB Output is correct
13 Correct 44 ms 2132 KB Output is correct
14 Correct 36 ms 344 KB Output is correct
15 Correct 37 ms 1364 KB Output is correct
16 Correct 35 ms 1364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 32 ms 848 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 32 ms 708 KB Output is correct
8 Correct 31 ms 344 KB Output is correct
9 Correct 27 ms 452 KB Output is correct
10 Correct 29 ms 444 KB Output is correct
11 Correct 41 ms 2080 KB Output is correct
12 Correct 41 ms 2116 KB Output is correct
13 Correct 44 ms 2132 KB Output is correct
14 Correct 36 ms 344 KB Output is correct
15 Correct 37 ms 1364 KB Output is correct
16 Correct 35 ms 1364 KB Output is correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 32 ms 848 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 32 ms 708 KB Output is correct
8 Correct 31 ms 344 KB Output is correct
9 Correct 27 ms 452 KB Output is correct
10 Correct 29 ms 444 KB Output is correct
11 Correct 41 ms 2080 KB Output is correct
12 Correct 41 ms 2116 KB Output is correct
13 Correct 44 ms 2132 KB Output is correct
14 Correct 36 ms 344 KB Output is correct
15 Correct 37 ms 1364 KB Output is correct
16 Correct 35 ms 1364 KB Output is correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 32 ms 848 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 32 ms 708 KB Output is correct
8 Correct 31 ms 344 KB Output is correct
9 Correct 27 ms 452 KB Output is correct
10 Correct 29 ms 444 KB Output is correct
11 Correct 41 ms 2080 KB Output is correct
12 Correct 41 ms 2116 KB Output is correct
13 Correct 44 ms 2132 KB Output is correct
14 Correct 36 ms 344 KB Output is correct
15 Correct 37 ms 1364 KB Output is correct
16 Correct 35 ms 1364 KB Output is correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 32 ms 848 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 32 ms 708 KB Output is correct
8 Correct 31 ms 344 KB Output is correct
9 Correct 27 ms 452 KB Output is correct
10 Correct 29 ms 444 KB Output is correct
11 Correct 41 ms 2080 KB Output is correct
12 Correct 41 ms 2116 KB Output is correct
13 Correct 44 ms 2132 KB Output is correct
14 Correct 36 ms 344 KB Output is correct
15 Correct 37 ms 1364 KB Output is correct
16 Correct 35 ms 1364 KB Output is correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Halted 0 ms 0 KB -