提出 #66566953


ソースコード 拡げる

#define _Alignof alignof
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

void solve() {
  ll n;
  cin >> n;
  string s;
  cin >> s;

  int idx = -1 ;
  for(int i = 0 ; i + 1< s.length() ; i++ ) {
    if(s[i] > s[i + 1]) {
        idx = i ;
        break ;
    }
  }
  if(idx == -1) {
    cout << s << endl;
    return;
  }
    
    int greaterdx = -1 ;
  for(int i = idx + 1 ; i < s.length() ; i++ ) {
    if(s[i] > s[idx]){
        greaterdx = i;
        break ;
    }
  }

  if(greaterdx == -1) {
    string res ;
    for(int i = 0 ; i < s.length() ;i++ ) {
        if(i != idx) res.pb(s[i]) ;
    }
    res.pb(s[idx]) ;
    cout << res << endl;
  } else{
    string res ;
    for(int i = 0 ;i < n ; i++ ) {
        if(i == greaterdx)res.pb(s[idx]) ;
        if(i != idx) res.pb(s[i]) ;
    }
    cout << res << endl;
  }


}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    // Uncomment the next line to read multiple test cases.
    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        
        // cout << "Case #" << t << ": ";
        solve();
    }
    return 0;
}

提出情報

提出日時
問題 D - String Rotation
ユーザ princeakanerd
言語 C++ 20 (gcc 12.2)
得点 400
コード長 2197 Byte
結果 AC
実行時間 21 ms
メモリ 3640 KiB

コンパイルエラー

Main.cpp: In function ‘void solve()’:
Main.cpp:44:24: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   44 |   for(int i = 0 ; i + 1< s.length() ; i++ ) {
      |                   ~~~~~^~~~~~~~~~~~
Main.cpp:56:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   56 |   for(int i = idx + 1 ; i < s.length() ; i++ ) {
      |                         ~~^~~~~~~~~~~~
Main.cpp:65:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   65 |     for(int i = 0 ; i < s.length() ;i++ ) {
      |                     ~~^~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 1
AC × 18
セット名 テストケース
Sample 00_sample_01.txt
All 00_sample_01.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 1 ms 3504 KiB
01_test_01.txt AC 20 ms 3500 KiB
01_test_02.txt AC 20 ms 3364 KiB
01_test_03.txt AC 21 ms 3476 KiB
01_test_04.txt AC 20 ms 3424 KiB
01_test_05.txt AC 2 ms 3608 KiB
01_test_06.txt AC 2 ms 3444 KiB
01_test_07.txt AC 2 ms 3520 KiB
01_test_08.txt AC 2 ms 3548 KiB
01_test_09.txt AC 1 ms 3584 KiB
01_test_10.txt AC 1 ms 3628 KiB
01_test_11.txt AC 1 ms 3516 KiB
01_test_12.txt AC 1 ms 3472 KiB
01_test_13.txt AC 1 ms 3620 KiB
01_test_14.txt AC 2 ms 3604 KiB
01_test_15.txt AC 2 ms 3640 KiB
01_test_16.txt AC 1 ms 3544 KiB
01_test_17.txt AC 6 ms 3560 KiB