"Duel!"

Betting on the lovely princess Claris, the duel between Tokitsukaze and Quailty has started.

There are nn cards in a row. Each card has two sides, one of which has color. At first, some of these cards are with color sides facing up and others are with color sides facing down. Then they take turns flipping cards, in which Tokitsukaze moves first. In each move, one should choose exactly kk consecutive cards and flip them to the same side, which means to make their color sides all face up or all face down. If all the color sides of these nn cards face the same direction after one's move, the one who takes this move will win.

Princess Claris wants to know who will win the game if Tokitsukaze and Quailty are so clever that they won't make mistakes.

Input

The first line contains two integers nn and kk (1≤k≤n≤1051≤k≤n≤105).

The second line contains a single string of length nn that only consists of 00 and 11, representing the situation of these nn cards, where the color side of the ii-th card faces up if the ii-th character is 11, or otherwise, it faces down and the ii-th character is 00.

Output

Print "once again" (without quotes) if the total number of their moves can exceed 109109, which is considered a draw.

In other cases, print "tokitsukaze" (without quotes) if Tokitsukaze will win, or "quailty" (without quotes) if Quailty will win.

Note that the output characters are case-sensitive, and any wrong spelling would be rejected.

Examples

Input
4 2
0101
Output
quailty
Input
6 1
010101
Output
once again
Input
6 5
010101
Output
tokitsukaze
Input
4 1
0011
Output
once again

解题思路:先手和后手要么一出手就赢,要么就会平局,因为两个人都聪明绝顶(暗示脱发),都想赢,如果一出手赢不了,然后两个人就可以重复同一步操作,抵消对方带来的不好影响,因此导致平局
先手必赢条件:1.不用翻转就可以赢
       2.翻转长度 k >= n ,那么只要翻转一次就可以赢
       3.k < n ,但是只要一次翻转就可以赢
后手赢的条件:那就是先手第一次无论怎么翻转都不能赢,但是到了后手无论何种情况下都能赢
        1.k!=1。因为如果先手赢不了,那他就相当于不动序列,留给后手,后手也赢不了
        2.2*k>=n,因为后手一出手必须赢,不然先手就可以抵消后手对于序列的影响而导致平局。
        3.2*k>=n的时候,那必定会存在一个区间k内的字符一定是相同的,考虑到先手(聪明绝顶,肯定不希望后手赢),那么我们只要让先手无论如何都会输就好了
        首尾肯定是不会选的,毕竟先手聪明绝顶。
        那么先手肯定会选择中间的k个连续字符,那么我们就枚举中间k个连续字符区间的左右的剩余区间(例如左边的是a区间,右边的是b区间。)我们判的是否a区间为都为0或者1,以及b。 因为先手决定聪明,所以他会尽量不让后手赢,所以就要枚举区间,判定没有一个情况下a和b不是合法的。
        并且区间a和区间b也必须是不同的
注意:判断后手赢得条件时,如果暴力判断(n2)会超时,因此用到里“窗体移动”的方法(这个是我在网上看到的,应该是这个叫法),区间k不断向右移动,同时保证左区间a和右区间b也满足条件
  要满足条件的话,去加入区间的元素,只要和它的上一位元素(或是下一位元素)比较就可以知道时候满足条件,这样的复杂度就降到了O(n),还有就是注意边界情况的处理。就是左区间或者右区间有且仅有1一个元素的时候,这个时候区间中没有东西可以进行比较,要满足的是区间a和区间b也必须是不同的。
 #include<bits/stdc++.h>
using namespace std;
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
const int P = ;
const int inf = 0x3f3f3f3f;
const int maxn = ;
vector<int>one,zero;
int n,k;
int str[maxn];
char s;
int check1(){
if(one.size() == || zero.size() == || k >= n){
return ;
}
int lz = -,rz = -,lo = -,ro = -;
for(int i = ; i <= n ; i++){
if(lz == - && str[i] == ){
lz = i;
}
if(lo == - && str[i] == ){
lo = i;
}
if(lz != - && lo != -) break;
}
for(int i = n ; i >= ; i--){
if(rz == - && str[i] == ){
rz = i;
}
if(ro == - && str[i] == ){
ro = i;
}
if(rz != - && ro != -) break;
}
if(k >= min(ro - lo + ,rz - lz + )) return ;
return ;
}
int check2(){
if(k == ) return ;
if( * k < n) return ;
int len = n - k;
for(int i = ; i < len ; i++){
if(str[i - ] != str[i - ] || str[i + k] != str[i + k + ]) return ;
}
if(str[] == str[n] || str[] == str[k+] || str[n] == str[n - k - ]) return ;
return ;
} int main(){
gbtb;
cin>>n>>k;
for(int i = ; i <= n ; i++){
cin>>s; str[i] = s-'';
if(str[i] == ) one.push_back(i);
else zero.push_back(i);
}
if(check1()){
cout<<"tokitsukaze"<<endl;
}else if(check2()){
cout<<"quailty"<<endl;
}else{
cout<<"once again"<<endl;
}
return ;
}

一个从很久以前就开始做的梦。

E - Tokitsukaze and Duel CodeForces - 1190C (博弈 + 窗体移动)的更多相关文章

  1. Tokitsukaze and Duel CodeForces - 1191E (博弈论)

    大意: 给定01串, 两人轮流操作, Tokitsukaze先手. 每次操作可以选择长为$k$的区间, 全部替换为$0$或$1$, 若替换后同色则赢. 求最后结果. 先判断第一步是否能直接赢, 不能的 ...

  2. Codeforces Round #573 (Div. 2) E. Tokitsukaze and Duel (博弈)

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. Codeforces 1190C. Tokitsukaze and Duel

    传送门 注意到后手可以模仿先手的操作,那么如果一回合之内没法决定胜负则一定 $\text{once again!}$ 考虑如何判断一回合内能否决定胜负 首先如果最左边和最右的 $0$ 或 $1$ 距离 ...

  4. Codeforces 1190C Tokitsukaze and Duel game

    题意:有一个长为n的01串,两个人轮流操作,每个人可以把某个长度为m的区间变成相同颜色,谁在操作后整个串颜色相同就赢了.问最后是谁赢?(有可能平局) 思路:容易发现,如果第一个人不能一击必胜,那么他就 ...

  5. Codeforces - 1191E - Tokitsukaze and Duel - 博弈论 - 尺取

    https://codeforc.es/contest/1191/problem/E 参考自:http://www.mamicode.com/info-detail-2726030.html 和官方题 ...

  6. C. Tokitsukaze and Duel 前缀维护

    枚举每一个连续的K的第一个位置,如果是先手胜利,那么前[1 , i-1 ]和[ i+k , n ]区间要么全是0,要么全是1 如果能够平局,那么肯定是[1,i-1],以及[ i+k , n]中有两种情 ...

  7. Codeforces 354B 博弈, DP,记忆化搜索

    题意:现在有一个字符矩阵,从左上角出发,每个人交替选择一个字符.如果最后字符a数目大于字符b,那么第一个人获胜,否则b获胜,否则平均.现在双方都不放水,问最后结果是什么? 思路:这题需要注意,选择的字 ...

  8. Ticket Game CodeForces - 1215D 博弈题

    题目描述 Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even ...

  9. Codeforces Round #573 (Div. 1)

    Preface 军训终于结束了回来补一补之前的坑发现很多题目题意都忘记了 这场感觉难度适中,F由于智力不够所以弃了,E的话石乐志看了官方英文题解才发现自己已经胡了一大半就差实现了233 水平下降严重. ...

随机推荐

  1. jmeter非GUI模式命令

    一.如果没有.jtl文件,运行如下命令: jmeter -n -t baidu.jmx -l result.jtl 以非GUI形式运行Jmeter脚本jmeter -n -t baidu.jmx -l ...

  2. Golang的类型转换实战案例

    Golang的类型转换实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.数据类型概述 基础数据类型概述,博主推荐阅读: 布尔型: https://www.cnblogs. ...

  3. mongodb单机版的安装和配置

    首先根据操作系统下载MongoDB的相关安装文件 下载后上传到linux上,解压 将解压后的文件夹重新命名为monggodb4.0.1 命令mv 配置必要的文件夹mgdata存放运行数据,mglog存 ...

  4. Spring配置数据源的三种方法

    前言:今天接触新项目发现用的是JNDI配置数据源,用度娘倒腾了一会也没弄好,只好用平常用的方法,结果发现BasicDataSource和DriverManagerDataSource也是不同的,所以记 ...

  5. Essay写作如何提升自己的辩驳水平?

    辩证思维在英文写作上的表现方式有许多种,今天来讲讲Counterargument&Rebut,广泛用于英文写作和口语辩论.其作用就是通过辩驳和你论点相反的意见,来突出自己的论点更正确. 话说衡 ...

  6. springmvc无法访问JS,CSS等文件

    配置好web.xml中的dispatchservlet后,js,css,都不能正常显示 web.xml配置文件 <!-- 核心控制器 --> <servlet> <ser ...

  7. java_05_IO

    java_05_IO 1,动手动脑 使用Files. walkFileTree()找出指定文件夹下所有大于指定大小(比如1M)的文件. 分析思路: 1)找到该文件夹下所有文件. 2)找出其中字节数大于 ...

  8. 中国移动携手华为百度展示5G应用,实现8K视频传输

    在今日举行的 2019 年百度云智峰会上,中国移动携手华为和百度,首次展示基于 SA 架构的 5G Vertical LAN (行业局域网)技术,承载 8K 实时会议系统,助力企业云办公.该技术可为合 ...

  9. windows driver 获取本地时间

    #define ArrayLength 260 void MyGetLocalTime() { LARGE_INTEGER li_system; LARGE_INTEGER li_Local; cha ...

  10. Java算法练习——最长回文子串

    题目链接 题目描述 给定一个字符串 s,找到 s 中最长的回文子串.你可以假设 s 的最大长度为 1000. 示例 1 输入: "babad" 输出: "bab" ...