爽玩
1. Find the Permutation
void solve(){
int n; cin >> n;
string s[n];
for(int i=0; i<n; i++) cin >> s[i];
int ans[n];
for(int i=0; i<n; i++){
ans[i] = i+1;
}
auto cmp = [&](int l, int r)->bool{
if(s[l-1][r-1] == '0'){
return l>r;
}else{
return l<r;
}
};
sort(ans, ans+n, cmp);
for(int i=0; i<n; i++){
cout << ans[i] << ' ';
}
cout << endl;
}
2
#define int long long
const int maxn = 2e5+10;
int n, k, stal, star, p[maxn], a[maxn];
int get_mx(int sta){
int ans = 0, cnt = 0, now = sta, val = a[sta], pre = 0;
while(1){
ans = max(ans, pre+(k-cnt)*val);
pre += val;
cnt++;
now = p[now];
val = a[now];
if(now == sta) break;
if(cnt == k) break;
}
return ans;
}
void solve(){
cin >> n >> k >> stal >> star;
for(int i=1; i<=n; i++){
cin >> p[i];
}
for(int k=1; k<=n; k++){
cin >> a[k];
}
int mxl = get_mx(stal);
int mxr = get_mx(star);
if(mxl > mxr) cout << "Bodya" << endl;
else if(mxl < mxr) cout << "Sasha" << endl;
else cout << "Draw" << endl;
}
int n;
struct node{
int x, y;
};
node dir[4] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
bool check(int x, int y){
return x>=0 && y>=0 && x<n && y<2;
}
void solve(){
cin >> n;
string a[2];
cin >> a[0] >> a[1];
vector<vector<bool>> vis(2, vector<bool>(n, false));
vis[0][0] = true;
queue<node> q;
q.push({0, 0});
while(!q.empty()){
auto [x, y] = q.front(); q.pop();
for(int i=0; i<4; i++){
int nx = x+dir[i].x, ny = y+dir[i].y;
if(check(nx, ny)){
if(a[ny][nx] == '<'){
nx--;
}else{
nx++;
}
if(check(nx, ny) && vis[ny][nx]==false){
vis[ny][nx] = true;
q.push({nx, ny});
}
}
}
}
if(vis[1][n-1]){
cout << "YES" << endl;
}else{
cout << "NO" << endl;
}
}