Submission #1159128


Source Code Expand

#include <iterator>
#include <array>
#include <vector>
#include <functional>
#include <map>
#include <utility>
#include <cstdio>
template<typename T> struct ScanfSpecifier{};
#define DEF(T,V) template<> struct ScanfSpecifier<T>{static constexpr const char* value = V;};
DEF(char*,"%s")DEF(int,"%d")DEF(double,"%lf")DEF(float,"%f")DEF(char,"%c")DEF(const char*,"%s")DEF(unsigned long,"%lu")DEF(unsigned int, "%u")
#ifdef _MSC_VER
DEF(long long int,"%I64d")
#else
DEF(long long int,"%lld")
#endif
#undef DEF
template<typename T> int RD(T& arg){return std::scanf(ScanfSpecifier<T>::value, &arg);}
template<int S> int RD(char (&arg)[S]){return std::scanf("%s", arg);}
int RD(char* arg){return std::scanf("%s", arg);}
template<> int RD<char>(char& arg){return std::scanf(" %c", &arg);}
template<typename T, typename... Args> int RD(T& arg1, Args&... args) {return RD(arg1) + RD(args...);}
template<typename T> T RD(){T ret; RD(ret); return ret;}
template<typename It> void RDV(It begin, It end) { while(begin != end) RD(*begin++); }
template<typename C> void RDV(C& c) {RDV(std::begin(c), std::end(c));}
template<typename T> void WT(T arg) {std::printf(ScanfSpecifier<T>::value, arg); }
template<typename T, typename U> void WT(std::pair<T, U> arg) {std::printf("("); WT(arg.first); std::printf(", "); WT(arg.second); std::printf(")");}
template<typename... Args> void WT(Args... args) { int alc = 0; int dummy[] = {((alc++? std::printf(" "): 0), WT(args), 0)...}; }

template<typename... Args> void WTL(Args... args) { WT(args...); std::printf("\n"); }
template<typename It> void WTV(It begin, It end) { int alc = 0; while(begin != end) (alc++? std::printf(" "): 0), WT(*begin++); }
template<typename C> void WTV(const C& c) {WTV(std::begin(c), std::end(c));}
template<typename It> void WTVL(It begin, It end) { WTV(begin, end); std::printf("\n"); }
template<typename C> void WTVL(const C& c) {WTVL(std::begin(c), std::end(c));}




template<typename T>
struct Mapper
{
    int operator[](const T& v) { int& ret = table[v]; if(!ret) rtable[ret = table.size()] = v; return ret - 1; }
    template<typename... Args> int operator()(Args... args) { return (*this)[T(args...)]; }
    T rev(int idx){return rtable[idx + 1];}
    std::map<T, int> table;
    std::map<int, T> rtable;
};

template<typename T, int S>
struct ReferenceArray
{
    struct It {typename std::array<T*, S>::iterator it; T& operator*(){return **it;} void operator++(){it++;} bool operator!=(const It& other){return it != other.it;} };
    int size()const{return _ptr.size();}
    It begin()const{return {_ptr.begin()};}
    It end()const{return {_ptr.end()};}
    T& operator[](int idx)const{return *_ptr[idx];}
    mutable std::array<T*, S> _ptr;
};
template<typename T, typename... Args> 
ReferenceArray<T, sizeof...(Args) + 1> MAKEV(T& arg1, Args&... args) {return {&arg1, &args...};}

struct Range
{   
    struct It {   int num, step; int operator*(){return num;} void operator++(){num += step;} bool operator!=(const It& other){return num != other.num;} };
    Range(int ee):b(0),e(ee){}
    Range(int bb, int ee):b(bb), e(ee){}
    It begin(){return {b, (b < e? 1: -1)};}
    It end(){return {e, 0};}
    int b, e;
};

template<typename T> inline T& UMAX(T& x, T y){if(x < y)x = y; return x;}
template<typename T> inline T& UMIN(T& x, T y){if(y < x)x = y; return x;}
template<typename T, typename... Args> struct ArithmiticPromotion { typedef decltype(T() + typename ArithmiticPromotion<Args...>::type()) type; };
template<typename T, typename U> struct ArithmiticPromotion<T, U> { typedef decltype(T() + U()) type; };
template<typename T> struct ArithmiticPromotion<T, T> { typedef T type; };
template<typename T> struct ArithmiticPromotion<T> { typedef T type; };
template<typename T, typename U> typename ArithmiticPromotion<T, U>::type MAX(T a, U b) { return a < b? b: a; }
template<typename T, typename... Args> typename ArithmiticPromotion<T, Args...>::type MAX(T a, Args... args) { return MAX(a, MAX(args...)); }
template<typename T, typename U> typename ArithmiticPromotion<T, U>::type MIN(T a, U b) { return a < b? a: b; }
template<typename T, typename... Args> typename ArithmiticPromotion<T, Args...>::type MIN(T a, Args... args) { return MIN(a, MIN(args...)); }





//alias
//RD[L],RDV[L],WT[L],WTV[L] for i/o
using RG = Range;
//template
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <cstdlib>
#include <algorithm>
#include <functional>
using namespace std;

char S[200009];
char ans[200009];
int N, K;



int main()
{
    RD(N, K, S);
    for(int i: RG(N))
        S[i] -= 'A';
    S[N] = 1;

    int start = 0;
    for(int i: RG(N))
        if(S[N - 1 - i] != i % 2)
        {
            start = i;
            break;
        }

    int L = N - 1 - start + 1;

    int pos = 0;
    int head = S[0];
    int total = 0;
    for(int i = 0; pos < L && i < K; i++, total++)
    {
        if(head == 0)
            head ^= 1;
        else 
        {
            if((S[1 + pos] ^ ((pos & 1))) == head)
                head ^= 1;
            pos++;
        }    
    }


    for(int i = 1; i < L; i++)
    {
        int len = L - i;
        int to = i + min(pos, len);
        ans[i] = 'A' + (S[to] ^ ((to - i) & 1));
    }
    
    if(N & 1)
        ans[0] = 'A' + (head ^ ((K - total) & 1));
    else
        ans[0] = 'A' + head;

    for(int i = L; i < N; i++)
        ans[i] = S[i] + 'A';
    for(int i = L; i < N; i++)
        ans[i] = S[i] + 'A';
    WTL(ans);



}




Submission Info

Submission Time
Task D - Half Reflector
User bigINnnner
Language C++14 (GCC 5.4.1)
Score 900
Code Size 5666 Byte
Status AC
Exec Time 4 ms
Memory 768 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 50
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in41.txt, in42.txt, in5.txt, in543.txt, in557.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
in1.txt AC 0 ms 128 KB
in10.txt AC 2 ms 768 KB
in11.txt AC 3 ms 768 KB
in12.txt AC 2 ms 768 KB
in13.txt AC 2 ms 768 KB
in14.txt AC 3 ms 768 KB
in15.txt AC 2 ms 768 KB
in16.txt AC 2 ms 768 KB
in17.txt AC 3 ms 768 KB
in18.txt AC 2 ms 768 KB
in19.txt AC 2 ms 768 KB
in2.txt AC 1 ms 512 KB
in20.txt AC 3 ms 768 KB
in21.txt AC 2 ms 768 KB
in22.txt AC 3 ms 768 KB
in23.txt AC 3 ms 768 KB
in24.txt AC 3 ms 768 KB
in25.txt AC 3 ms 768 KB
in26.txt AC 3 ms 768 KB
in27.txt AC 3 ms 768 KB
in28.txt AC 2 ms 768 KB
in29.txt AC 4 ms 768 KB
in3.txt AC 3 ms 768 KB
in30.txt AC 2 ms 768 KB
in31.txt AC 2 ms 768 KB
in32.txt AC 2 ms 768 KB
in33.txt AC 3 ms 768 KB
in34.txt AC 3 ms 768 KB
in35.txt AC 3 ms 768 KB
in36.txt AC 3 ms 768 KB
in37.txt AC 3 ms 768 KB
in38.txt AC 3 ms 768 KB
in39.txt AC 2 ms 768 KB
in4.txt AC 3 ms 768 KB
in40.txt AC 2 ms 768 KB
in41.txt AC 2 ms 768 KB
in42.txt AC 2 ms 768 KB
in5.txt AC 3 ms 768 KB
in543.txt AC 2 ms 768 KB
in557.txt AC 2 ms 768 KB
in6.txt AC 0 ms 128 KB
in7.txt AC 3 ms 768 KB
in8.txt AC 3 ms 768 KB
in9.txt AC 3 ms 768 KB
sample1.txt AC 0 ms 128 KB
sample2.txt AC 0 ms 128 KB
sample3.txt AC 0 ms 128 KB