Submission #2834910
Source Code Expand
#include<bits/stdc++.h> using namespace std; #define P(p) cout<<(p)<<endl #define rep(i,m,n) for(int i = (m); i < (int)(n); i++) #define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define vsort(v) sort(v.begin(), v.end()); #define rvsort(v) sort(v.begin(), v.end(),greater<int>()); #define YES cout<<"YES"<< endl #define NO cout<<"NO"<<endl #define Yes cout<<"Yes"<<endl #define No cout<<"No"<<endl #define yes cout<<"yes"<<endl #define no cout<<"no"<<endl #define ret return #define lb(v,n) lower_bound(v.begin(),v.end(),n) #define ub(v,n) upper_bound(v.begin(),v.end(),n) #define mae(v) max_element(v.begin(),v.end()) #define mie(v) min_element(v.begin(),v.end()) #define INF 0x7FFFFFFF #define mod 1000000007 typedef long long ll; //////////////////////////////////////////////////////////// int main(){ int n; cin >> n; string s; cin >> s; cin >> s; if( n == 1 ){ cout << 3 << endl; ret 0; } stack<char> st; vector<short> v; rep(i,0,n){ if( st.size() == 0 ) st.push(s[i]); else{ if( s[i] == st.top() ){ v.push_back(2); st.pop(); } else{ v.push_back(1); st.pop(); st.push(s[i]); } } } if( st.size() > 0 ) v.push_back(1); //rep(i,0,v.size()) cout << v[i]; //cout << endl; ll ans; if( v[0] == 1 ) ans = 3; else ans = 6; short bef = v[0]; rep(i,1,v.size()){ if( bef == 1 ) ans *= 2; else{ if( v[i] == 2 ) ans *= 3; } bef = v[i]; ans %= mod; } cout << ans << endl; ret 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Coloring Dominoes |
User | walk_to_work |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1550 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 |