Submission #7215418


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    #define double long double
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    void chmax(int &x,const ll y) {x=(x>y?x:y);}
    void chmin(int &x,const ll y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):0;}
    const int INF=0x3f3f3f3f;
    const int MOD=998244353;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    inline ll qpower(ll x,ll e)
    {
        ll ans=1;
        while(e)
        {
            if(e&1) ans=ans*x%MOD;
            x=x*x%MOD;e>>=1;
        }
        return ans;
    }
    inline int invm(int x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    char str[N];int n;
    int getmi(int a,int b)
    {
        int ta=a,tb=b;
        while(str[a]==str[b]) a++,b++;
        return str[a]<str[b]?ta:tb;
    }
    vc<char> ans,ans2;
    void main()
    {
        int n=qread(),k=qread()-1;scanf("%s",str);
        for(int i=n;i<n+n;i++) str[i]=str[i-n];reverse(str+n,str+n+n);
        int mi=0;for(int i=1;i<=n;i++) mi=getmi(mi,i);
        int cnt=0;while(cnt<n and str[mi]==str[mi+cnt]) cnt++;
        // printf("cnt=%d\n",cnt);
        mi=(n+n-1-mi)-n+1;for(int i=mi;i<mi+n;i++) ans.PB(str[i]);
        while(k--)
        {
            ans2.clear();
            if(cnt*2>=n)
            {
                int t=n;while(t--) ans2.PB(ans[n-1]);swap(ans,ans2);
                break;
            }
            int st=n-1-(n-cnt)+1,op=1;
            int pp=n;while(pp--) {ans2.PB(ans[st]);st+=op;if(st==n)st--,op=-1;}
            swap(ans,ans2);cnt*=2;
            // puts("");
        }
        for(int t=sz(ans)-1;t>=0;t--) putchar(ans[t]);
    }
};
int main()
{
    srand(time(0));
    mine::main();
}

Submission Info

Submission Time
Task E - Reversing and Concatenating
User Zory
Language C++14 (GCC 5.4.1)
Score 1300
Code Size 2479 Byte
Status
Exec Time 3 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘void mine::main()’:
./Main.cpp:60:50: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         int n=qread(),k=qread()-1;scanf("%s",str);
                                                  ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample01.txt, sample02.txt
All 1300 / 1300 sample01.txt, sample02.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt, in48.txt, in49.txt, in50.txt, in51.txt, in52.txt, in53.txt, in54.txt, in55.txt, in56.txt, in57.txt, in58.txt, in59.txt, in60.txt, in61.txt, in62.txt, in63.txt, in64.txt, in65.txt, in66.txt, in67.txt, in68.txt, in69.txt, in70.txt, in71.txt, in72.txt, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
in01.txt 1 ms 256 KB
in02.txt 1 ms 256 KB
in03.txt 1 ms 256 KB
in04.txt 1 ms 256 KB
in05.txt 1 ms 256 KB
in06.txt 1 ms 256 KB
in07.txt 1 ms 256 KB
in08.txt 1 ms 256 KB
in09.txt 1 ms 256 KB
in10.txt 1 ms 256 KB
in11.txt 1 ms 256 KB
in12.txt 1 ms 256 KB
in13.txt 1 ms 256 KB
in14.txt 1 ms 256 KB
in15.txt 1 ms 256 KB
in16.txt 1 ms 256 KB
in17.txt 1 ms 256 KB
in18.txt 1 ms 256 KB
in19.txt 1 ms 256 KB
in20.txt 1 ms 256 KB
in21.txt 1 ms 256 KB
in22.txt 1 ms 256 KB
in23.txt 1 ms 256 KB
in24.txt 1 ms 256 KB
in25.txt 1 ms 256 KB
in26.txt 1 ms 256 KB
in27.txt 1 ms 256 KB
in28.txt 1 ms 256 KB
in29.txt 1 ms 256 KB
in30.txt 1 ms 256 KB
in31.txt 1 ms 256 KB
in32.txt 1 ms 256 KB
in33.txt 1 ms 256 KB
in34.txt 1 ms 256 KB
in35.txt 1 ms 256 KB
in36.txt 1 ms 256 KB
in37.txt 3 ms 256 KB
in38.txt 1 ms 256 KB
in39.txt 1 ms 256 KB
in40.txt 1 ms 256 KB
in41.txt 2 ms 256 KB
in42.txt 2 ms 256 KB
in43.txt 1 ms 256 KB
in44.txt 1 ms 256 KB
in45.txt 1 ms 256 KB
in46.txt 2 ms 256 KB
in47.txt 1 ms 256 KB
in48.txt 2 ms 256 KB
in49.txt 2 ms 256 KB
in50.txt 2 ms 256 KB
in51.txt 1 ms 256 KB
in52.txt 1 ms 256 KB
in53.txt 2 ms 256 KB
in54.txt 1 ms 256 KB
in55.txt 1 ms 256 KB
in56.txt 1 ms 256 KB
in57.txt 1 ms 256 KB
in58.txt 2 ms 256 KB
in59.txt 1 ms 256 KB
in60.txt 1 ms 256 KB
in61.txt 1 ms 256 KB
in62.txt 1 ms 256 KB
in63.txt 1 ms 256 KB
in64.txt 2 ms 256 KB
in65.txt 1 ms 256 KB
in66.txt 1 ms 256 KB
in67.txt 1 ms 256 KB
in68.txt 2 ms 256 KB
in69.txt 1 ms 256 KB
in70.txt 1 ms 256 KB
in71.txt 1 ms 256 KB
in72.txt 1 ms 256 KB
sample01.txt 1 ms 256 KB
sample02.txt 1 ms 256 KB