Submission #3215118
Source Code Expand
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>
using namespace std;
#define countof(a) (sizeof(a)/sizeof(*a))
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define fi first
#define se second
#define all(n) n.begin(), n.end()
#define FOR(var, to) for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)
#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()
#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)
#define MOD 1000000007
#define INF (1 << 30)
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
template<int mod>
struct ModInt{
int x;
ModInt():x(0){}
ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
ModInt &operator+=(const ModInt &p){
if((x+=p.x)>=mod)x-=mod;
return *this;
}
ModInt &operator-=(const ModInt &p){
if((x+=mod-p.x)>=mod)x-=mod;
return *this;
}
ModInt &operator*=(const ModInt &p){
x=(int)(1LL*x*p.x%mod);
return *this;
}
ModInt &operator/=(const ModInt &p){
*this*=p.inverse();
return *this;
}
ModInt operator-()const{return ModInt(-x);}
ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
bool operator==(const ModInt &p)const{return x==p.x;}
bool operator!=(const ModInt &p)const{return x!=p.x;}
ModInt inverse()const{
int a=x,b=mod,u=1,v=0,t;
while(b>0){
t=a/b;
a-=t*b;
swap(a,b);
u-=t*v;
swap(u,v);
}
return ModInt(u);
}
friend ostream &operator<<(ostream &os,const ModInt<mod> &p){
return os<<p.x;
}
friend istream &operator>>(istream &is,ModInt<mod> &a){
long long x;
is>>x;
a=ModInt<mod>(x);
return (is);
}
};
typedef ModInt<MOD> mint;
struct UnionFind{
vi data;
UnionFind(int size):data(size,-1){}
bool unite(int x,int y) {
x=root(x);y=root(y);
if(x!=y){
if(data[y]<data[x])swap(x,y);
data[x]+=data[y];data[y]=x;
}
return x!=y;
}
bool find(int x,int y) {
return root(x)==root(y);
}
int root(int x) {
return data[x]<0?x:data[x]=root(data[x]);
}
int size(int x) {
return -data[root(x)];
}
bool united() {
int comroot = -1;
FOR(i,data.size()) {
if (comroot != -1 && root(i) != comroot) return false;
comroot = root(i);
}
return true;
}
};
static inline int ri() {
int a;
scanf("%d", &a);
return a;
}
static inline s64 rs64() {
s64 a;
scanf("%" SCNd64, &a);
return a;
}
static inline void wi(int a) {
printf("%d", a);
}
static inline void wu64(u64 a) {
printf("%" PRIu64, a);
}
static inline void ws64(s64 a) {
printf("%" PRId64, a);
}
int int_less(const void *a, const void *b) {
return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
return (*((const int*)b) - *((const int*)a));
}
int main() {
int n;cin>>n;
string s1;cin>>s1;
string s2;cin>>s2;
int pos = 0;
mint res = 1;
bool last_1;
while(pos<n) {
if (s1[pos] == s2[pos]) {
if (!pos) res *= 3;
else if (last_1) res *= 2;
last_1 = s1[pos] == s2[pos];
pos++;
} else {
if (!pos) res *= 6;
else if (last_1) res *= 2;
else res *= 3;
last_1 = s1[pos] == s2[pos];
pos += 2;
}
// last_1 = s1[pos] == s2[pos];
}
cout << res << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Coloring Dominoes |
User |
QCFium |
Language |
C++14 (GCC 5.4.1) |
Score |
400 |
Code Size |
4493 Byte |
Status |
AC |
Exec Time |
1 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
400 / 400 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample1.txt, sample2.txt, sample3.txt |
All |
sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name |
Status |
Exec Time |
Memory |
1.txt |
AC |
1 ms |
256 KB |
10.txt |
AC |
1 ms |
256 KB |
11.txt |
AC |
1 ms |
256 KB |
12.txt |
AC |
1 ms |
256 KB |
13.txt |
AC |
1 ms |
256 KB |
14.txt |
AC |
1 ms |
256 KB |
15.txt |
AC |
1 ms |
256 KB |
16.txt |
AC |
1 ms |
256 KB |
17.txt |
AC |
1 ms |
256 KB |
18.txt |
AC |
1 ms |
256 KB |
19.txt |
AC |
1 ms |
256 KB |
2.txt |
AC |
1 ms |
256 KB |
20.txt |
AC |
1 ms |
256 KB |
21.txt |
AC |
1 ms |
256 KB |
22.txt |
AC |
1 ms |
256 KB |
3.txt |
AC |
1 ms |
256 KB |
4.txt |
AC |
1 ms |
256 KB |
5.txt |
AC |
1 ms |
256 KB |
6.txt |
AC |
1 ms |
256 KB |
7.txt |
AC |
1 ms |
256 KB |
8.txt |
AC |
1 ms |
256 KB |
9.txt |
AC |
1 ms |
256 KB |
sample1.txt |
AC |
1 ms |
256 KB |
sample2.txt |
AC |
1 ms |
256 KB |
sample3.txt |
AC |
1 ms |
256 KB |