- Published on
Codeforces Round 927
A. Thorns and Coins
straightforward problem
void test_case() {
int n; cin >> n;
string s; cin >> s;
int ans = 0;
int thorn = 0;
for(int i = 0; i < n; i++){
if(s[i] == '@') ans++;
if(s[i] == '*'){
thorn++;
}else{
thorn = 0;
}
if(thorn >= 2)
break;
}
cout << ans << nl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int t = 1;
cin >> t;
while (t--) test_case();
}
B - Chaya Calendar
math problem
void test_case() {
int n; cin >> n;
vector<int> vi(n);
for(auto&a : vi) cin >> a;
int curr = 0;
for(int i = 0; i < vi.size()-1; i++){
curr = vi[i];
int next = curr / vi[i+1];
vi[i+1]*= next + 1;
debug(vi);
}
cout << vi[n-1] << nl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int t = 1;
cin >> t;
while (t--) test_case();
}
C. LR-remainders
this took me forever cause i suck at implementation, but its basically a two pointer problem
void test_case() {
int n, m; cin >> n >> m;
vector<int> vi(n);
for(auto &a: vi) cin >> a;
string s; cin >> s;
vector<int> operation(n);
int lc = 0;
int rc = 0;
for(int i = 0; i < n; i++){
if(s[i] == 'L'){
operation[i] = lc;
lc++;
} else{
operation[i] = rc;
rc++;
}
}
ll modd = 1;
vector<int> ans;
for(int i = n-1; i >= 0; i--){
int op = operation[i];
if(s[i] == 'L'){
modd*= vi[op];
} else{
modd*= vi[n-op-1];
}
modd%=m;
ans.push_back(modd);
}
for(int i = ans.size()-1; i >= 0; i--){
cout << ans[i] << " ";
}
cout << nl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int t = 1;
cin >> t;
while (t--) test_case();
}
D. Card Game
Pretty cool implementation problem
void test_case() {
int n; cin >> n;
char trump; cin >> trump;
vector<string> vi(2*n);
map<char, vector<string>> howmany;
vector<string> trumpstring;
for(auto&a: vi){
cin >> a;
if(a[1] != trump){
howmany[a[1]].push_back(a);
} else{
trumpstring.push_back(a);
}
}
int trumpnum = trumpstring.size();
int odd = 0;
for(auto&a: howmany){
if(a.second.size()%2 == 1){
odd++;
}
}
if(odd > trumpnum){
cout << "IMPOSSIBLE" << nl;
return;
}
sort(all(trumpstring));
vector<string> match;
for(auto&a: howmany){
sort(all(a.second));
if(a.second.size()%2 == 1){
match.push_back(a.second[a.second.size()-1]);
a.second.pop_back();
}
if(a.second.size() >= 2){
for(int i = 0; i < a.second.size(); i+=2){
cout << a.second[i] << " " << a.second[i+1] << nl;
}
}
}
sort(all(match));
for(int i = 0; i < match.size(); i++){
cout << match[i] << " " << trumpstring[i] << nl;
}
for(int j = match.size(); j < trumpstring.size(); j+=2){
cout << trumpstring[j] << " " << trumpstring[j+1] << nl;
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int t = 1;
cin >> t;
while (t--) test_case();
}
E. Final Countdown
also a math problem
void test_case() {
int n; cin >> n;
string s; cin >> s;
int sum = 0;
for(int i = 0; i < s.size()-1; i++){
sum += s[i]-'0';
}
int carry = 0;
for(int i = s.size()-1; i>=0; i--){
int cur = s[i]-'0';
int temp = s[i-1]-'0';
cur = cur+sum+carry;
carry = cur/10;
cur%=10;
sum-=temp;
s[i] = (int)(cur+'0');
}
if(carry){
s = char(carry+'0') + s;
}
int i = 0;
while(s[i] == '0'){
i++;
}
s.erase(0, i);
cout << s << nl;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
int t = 1;
cin >> t;
while (t--) test_case();
}