提出 #43420333


ソースコード 拡げる

// LUOGU_RID: 114614046
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e6 + 10;
int k,n,m;
int bas[20];
char str[maxn];
namespace tire
{
	int son[maxn][3],val[maxn],tag[maxn],ans[maxn],tot;
	void build(int u,int d,int now)
	{
		if(d == k)
		{
			val[u] = now;
			return ;
		}
		for(int i = 0;i <= 2;i++)
		{
			son[u][i] = ++tot;
			build(son[u][i],d + 1,now + i * bas[d]);
		}
	}
	void push_down(int u)
	{
		if(!tag[u])
		{
			return ;
		}
		swap(son[u][1],son[u][2]);
		for(int i = 0;i <= 2;i++)
		{
			tag[son[u][i]] ^= 1;
		}
		tag[u] = 0;
	}
	void add(int u)
	{
		if(!son[u][0])
		{
			return ;
		}
		push_down(u);
		int v = son[u][0];
		son[u][0] = son[u][2];
		son[u][2] = son[u][1];
		son[u][1] = v;
		add(son[u][0]);
	}
	void dfs(int u,int d,int now)
	{
		if(d == k)
		{
			ans[val[u]] = now;
			return ;
		}
		push_down(u);
		for(int i = 0;i <= 2;i++)
		{
			dfs(son[u][i],d + 1,now + i * bas[d]);
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin >> k;
	bas[0] = 1;
	for(int i = 1;i <= k;i++)
	{
		bas[i] = bas[i - 1] * 3;
	}
	n = bas[k];
	cin >> str + 1;
	m = strlen(str + 1);
	tire::build(0,0,0);
	for(int i = 1;i <= m;i++)
	{
		if(str[i] == 'S')
		{
			tire::tag[0] ^= 1;
		}
		else
		{
			tire::add(0);
		}
	}
	tire::dfs(0,0,0);
	for(int i = 0;i < n;i++)
	{
		cout << tire::ans[i] << ' ';
	}
	return 0;
}

提出情報

提出日時
問題 C - Strange Dance
ユーザ feather_life
言語 C++ (GCC 9.2.1)
得点 1000
コード長 1462 Byte
結果 AC
実行時間 114 ms
メモリ 22016 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:75:13: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
   75 |  cin >> str + 1;
      |         ~~~~^~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 1000 / 1000
結果
AC × 3
AC × 16
セット名 テストケース
Sample example0.txt, example1.txt, example2.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, example0.txt, example1.txt, example2.txt
ケース名 結果 実行時間 メモリ
000.txt AC 15 ms 3520 KiB
001.txt AC 1 ms 3496 KiB
002.txt AC 3 ms 3500 KiB
003.txt AC 2 ms 3556 KiB
004.txt AC 4 ms 3512 KiB
005.txt AC 101 ms 21864 KiB
006.txt AC 87 ms 21944 KiB
007.txt AC 99 ms 21900 KiB
008.txt AC 73 ms 22016 KiB
009.txt AC 114 ms 21940 KiB
010.txt AC 62 ms 18824 KiB
011.txt AC 91 ms 18824 KiB
012.txt AC 79 ms 19868 KiB
example0.txt AC 7 ms 3448 KiB
example1.txt AC 3 ms 3532 KiB
example2.txt AC 3 ms 3520 KiB