제출 #889809

#제출 시각아이디문제언어결과실행 시간메모리
889809vjudge1Chorus (JOI23_chorus)C++17
16 / 100
44 ms2132 KiB
#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? */

컴파일 시 표준 에러 (stderr) 메시지

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);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...