Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define FOR(i, a, b) for(auto i=a; i<=b; ++i)
- #define REP(i, a, b) for(auto i=a; i<b; ++i)
- #define FORI(i, a, b) for(auto i=a; i!=b+1-2*(a>b); i+=1-2*(a>b))
- #define REPI(i, a, b) for(auto i=a-(a>b); i!=b-(a>b); i+=1-2*(a>b))
- using namespace std;
- class BearPasswordAny
- {
- public:
- string findPassword(vector<int> val)
- {
- string result = "";
- int N = val.size(), calc;
- char ch = 'a';
- for(int i=N-1; i>=0; --i)
- {
- calc = find_occur(result, i+1);
- // cout<<val[i]<<" "<<calc<<endl;
- if(calc > val[i])
- return "";
- while(val[i] - calc)
- {
- FOR(j, 0, i)
- result += ch;
- ch = 'b' - ch + 'a';
- ++calc;
- }
- // cout<<result<<endl;
- }
- if(result.size() != N)
- return "";
- return result;
- }
- int find_occur(string &str, int num)
- {
- int cnt = 1, ret = 0;
- if(!str.empty() && cnt >= num)
- ++ret;
- REP(i, 1, str.size())
- {
- if(str[i] == str[i-1])
- ++cnt;
- else
- cnt = 1;
- if(cnt >= num)
- ++ret;
- }
- return ret;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement