A - Bingo Ties
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 511;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
int n;
int a[M][11];
int vis[N];
bool ok;
inline void judge(int u,int v){
for(int i=1;i<=5;i++) vis[a[u][i]]++;
for(int i=1;i<=5;i++) vis[a[v][i]]++;
bool flag=0;
for(int i=1;i<=5;i++){
if(vis[a[v][i]]==2){
bool book=0;
for(int j=1;j<=5*n;j++){
if(j==u||j==v) continue;
else{
int temp=0;
for(int k=1;k<=5;k++){
if(vis[a[j][k]]&&a[j][k]!=a[v][i]) temp++;
}
if(temp==5){
book=1;
break;
}
}
}
if(!book){
flag=1;
break;
}
}
}
for(int i=1;i<=5;i++) vis[a[u][i]]--;
for(int i=1;i<=5;i++) vis[a[v][i]]--;
if(!flag) return ;
cout<<(u-1)/5+1<<" "<<(v-1)/5+1<<endl;
ok=1;
}
inline void solve(){
cin>>n;
for(int i=1;i<=n*5;i++){
for(int j=1;j<=5;j++){
cin>>a[i][j];
}
}
for(int i=1;i<=n*5;i++){
for(int j=i+1;j<=n*5;j++){
if((i-1)/5!=(j-1)/5){
if(!ok) judge(i,j);
else return ;
}
}
}
if(!ok) cout<<"no ties"<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
B - Das Blinkenlights
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
inline void solve(){
int p,q,s;
cin>>p>>q>>s;
int g=__gcd(q,p);
int sum=p*q/g;
if(sum<=s) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
G - Left and Right
答案
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#define ll long long
#define mem(a, b) memset(a, b, sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i, a, b) for (auto i = a; i <= b; ++i)
#define bep(i, a, b) for (auto i = a; i >= b; --i)
#define lowbit(x) x&(-x)
#define PII pair<int, int>
#define x first
#define y second
#define PLL pair<ll, ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
using namespace std;
char s[N];
vector<int> rp;
// vector<int>lp;
vector<int> ans;
inline void solve() {
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
cin >> s[i];
if (s[i] == 'R') rp.eb(i);
// else lp.eb(i);
}
rp.eb(n - 1);
if(s[0]=='R'){
for (int i = 0; i < rp.size(); i++) {
if (!i)
ans.eb(rp[i] + 1);
else {
ans.eb(rp[i] + 1);
int len = rp[i] - rp[i - 1] - 1;
int key = rp[i];
while (len--) {
key--;
ans.eb(key + 1);
}
}
}
}
else{
for (int i = 0; i < rp.size(); i++) {
if (!i){
ans.eb(rp[i] + 1);
int len = rp[i];
int key = rp[i];
while (len--) {
key--;
ans.eb(key + 1);
}
}
else {
ans.eb(rp[i] + 1);
int len = rp[i] - rp[i - 1] - 1;
int key = rp[i];
while (len--) {
key--;
ans.eb(key + 1);
}
}
}
}
//cout << "::" << ans.size() << endl;
for (auto i : ans) cout << i << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
K - Run-Length Encoding, Run!
答案
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
#define mem(a,b) memset(a,b,sizeof a)
#define ull unsigned long long
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(auto i=a;i<=b;++i)
#define bep(i,a,b) for(auto i=a;i>=b;--i)
#define lowbit(x) x&(-x)
#define PII pair<int,int>
#define x first
#define y second
#define PLL pair<ll,ll>
#define PI acos(-1)
#define pb push_back
#define eb emplace_back
const double eps = 1e-6;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;
const int M = 111;
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
using namespace std;
inline void solve(){
string s;
cin>>s;
string ans="";
if(s=="E"){
cin>>s;
int num=1;
for(int i=1;i<s.size();i++){
if(s[i]==s[i-1]) num++;
else {
ans+=s[i-1];
ans+=(num+'0');
num=1;
}
}
ans+=s[s.size()-1];
ans+=(num+'0');
}
else if(s=="D"){
cin>>s;
int num=0;
char k;
for(int i=0;i<s.size();i++){
if(!isdigit(s[i])){
for(int i=1;i<=num;i++){
ans+=k;
}
k=s[i];
num=0;
}
else {
num=num*10+(s[i]-'0');
}
}
for(int i=1;i<=num;i++){
ans+=k;
}
}
cout<<ans<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}