結果

問題 No.1020 Reverse
ユーザー hanachanXhanachanX
提出日時 2020-04-12 14:10:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 2,576 ms
コンパイル使用メモリ 180,480 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 01:12:59
合計ジャッジ時間 3,529 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 5 ms
4,348 KB
testcase_08 AC 6 ms
4,348 KB
testcase_09 AC 5 ms
4,348 KB
testcase_10 AC 6 ms
4,348 KB
testcase_11 AC 7 ms
4,348 KB
testcase_12 AC 7 ms
4,348 KB
testcase_13 AC 7 ms
4,348 KB
testcase_14 AC 6 ms
4,348 KB
testcase_15 AC 6 ms
4,348 KB
testcase_16 AC 6 ms
4,348 KB
testcase_17 AC 7 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) printf("%d\n",(x));
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;
typedef string S;
template<class T> using V = vector<T>;
using I = int;
using VI = V<I>;
const int INF = 2e9;
const int64 MOD = 1e9 + 7;

template <class T> inline bool chmin(T& a, T b){if(a>b){a=b; return true;} return false;}
template <class T> inline bool chmax(T& a, T b){if(a<b){a=b; return true;} return false;}

void reverse(S& s , int first , int last){
    int i , j;
    for(i = first , j = last ; j >= i ; ++i ,--j){
        swap(s[i] , s[j]);
    }
}

int main(){
    int n , k; cin >> n >> k;
    S s; cin >> s;
    S s1 , s2 , s3;
    s1 = s.substr(0 , k-1);
    s2 = s.substr(k-1);
    
    if ( (n-k)%2 == 0 ) {
        reverse(s1 , 0 , k-2);
    }
    cout << s2 + s1 << endl;
}

0