Submission #7961551


Source Code Expand

Copy
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  string s,t; cin >> s >> t;
  string ans = "Yes";

  vvi sg(26), tg(26);
  for (int i = 0; i < s.size(); i++) {
    int num = s[i] - 'a';
    sg[num].push_back(i);// 文字 s[i] が s の何文字目にあるかを記録
    num = t[i] - 'a';
    tg[num].push_back(i);
  }
  rep(i, 26){
    if(sg[i].size() > 1){// 文字 i が s に複数含まれていたら
      for (int j = 1; j < sg[i].size(); j++) {
        // s中 の i に対応する t の文字は全て同じ文字の必要がある
        if(t[sg[i][j]] != t[sg[i][j-1]]) ans = "No";
      }
    }

    if(tg[i].size() > 1){
      for (int k = 1; k < tg[i].size(); k++) {
        if(s[tg[i][k]] != s[tg[i][k-1]]) ans = "No";
      }
    }
  }
  std::cout << ans << '\n';
}

Submission Info

Submission Time
Task C - String Transformation
User mushano
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1402 Byte
Status
Exec Time 22 ms
Memory 3080 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01, sample_02, sample_03
All 300 / 300 0_min0, 0_min1, 1_small0, 1_small1, 1_small2, 2_medium0, 2_medium1, 2_medium2, 2_medium3, 2_medium4, 3_max0, 3_max1, 3_max2, 3_max3, 3_max4, 3_max5, 3_max6, 3_max7, 3_max8, 3_max9, 5_hand0, sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_min0 1 ms 256 KB
0_min1 1 ms 256 KB
1_small0 1 ms 256 KB
1_small1 1 ms 256 KB
1_small2 1 ms 256 KB
2_medium0 17 ms 2568 KB
2_medium1 12 ms 1928 KB
2_medium2 4 ms 896 KB
2_medium3 15 ms 2696 KB
2_medium4 12 ms 2056 KB
3_max0 22 ms 2696 KB
3_max1 17 ms 3080 KB
3_max2 18 ms 2696 KB
3_max3 17 ms 2568 KB
3_max4 17 ms 2696 KB
3_max5 22 ms 2676 KB
3_max6 17 ms 2288 KB
3_max7 17 ms 2288 KB
3_max8 17 ms 2284 KB
3_max9 17 ms 2588 KB
5_hand0 1 ms 256 KB
sample_01 1 ms 256 KB
sample_02 1 ms 256 KB
sample_03 1 ms 256 KB