이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* Arthur Conmy / arthurconmy */
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>
#include <deque>
#include <chrono>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<int,int> pii;
#define REP(i, a, b) for (int i = int(a); i <= int(b); i++)
#define REPb(j, d, c) for (int j = int(d); j >= int(c); j--)
#define ff first
#define ss second
#define pb push_back
#define len(x) int((x).size())
#define endl "\n"
int main() // LL OR INT?? DELETED IFSTREAM??
{
#ifdef LOCAL
ifstream cin("input.txt");
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin>>n>>m;
string s;
cin>>s;
int a=1;
int b=0;
int c=1;
int cur=1; // cur is placement in CURRENT group ??? YES
char cur_group;
if(s[0]=='L')
{
cur_group='a';
}
if(s[0]=='P')
{
cur_group='c';
}
REP(i,1,n-1)
{
//cout << i << " " << cur << " " << cur_group << endl;
a+=m;
b+=m;
c+=m;
cur+=m;
a%=m;
b%=m;
c%=m;
cur%=m;
if(i%2 == 1)
{
int new_a = 2*a - 1;
int new_b = b+2;
int new_c = 2*c - 1;
if(cur_group == 'a')
{
if(cur==a && s[i]=='P')
{
cur=1;
cur_group='b';
a=new_a;
b=new_b;
c=new_c;
continue;
}
cur = cur*2;
if(s[i]=='L') cur--;
a=new_a;
b=new_b;
c=new_c;
continue;
}
if(cur_group=='b')
{
cur++;
a=new_a;
b=new_b;
c=new_c;
continue;
}
if(cur_group=='c')
{
if(cur==1 && s[i]=='L')
{
cur_group='b';
cur=new_b;
a=new_a;
b=new_b;
c=new_c;
continue;
}
cur = cur*2;
cur--;
if(s[i]=='L') cur--;
a=new_a;
b=new_b;
c=new_c;
continue;
}
}
if(i%2==0)
{
int new_a = a + 1;
int new_b = 2*b - 2;
int new_c = c + 1;
if(cur_group=='a')
{
a=new_a;
b=new_b;
c=new_c;
continue;
}
if(cur_group=='b')
{
if(cur==1 && s[i]=='L')
{
cur=a+1;
cur_group='a';
a=new_a;
b=new_b;
c=new_c;
continue;
}
if(cur==b && s[i]=='P')
{
cur=1;
cur_group='c';
a=new_a;
b=new_b;
c=new_c;
continue;
}
// otherwise we'll remain in B
cur = 2*(cur-1);
if(s[i]=='P') cur++;
a=new_a;
b=new_b;
c=new_c;
continue;
}
if(cur_group=='c')
{
cur++;
a=new_a;
b=new_b;
c=new_c;
continue;
}
}
}
//cout << a << " " << b << " " << c << endl << endl;
//cout << cur << " " << cur_group << endl;
if(cur_group=='a')
{
cout << cur%m << endl;
}
if(cur_group=='b')
{
cout << (cur + a)%m << endl;
}
if(cur_group=='c')
{
cout << (cur + a + b)%m << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |