fork download
  1. // بسم الله الرحمن الرحيم
  2. //متنساش تصل على النبي -صلى الله عليه وسلم- بس كده
  3.  
  4.  
  5.  
  6. // ===================== CORE =====================
  7. #include <bits/stdc++.h>
  8. #include <ext/pb_ds/assoc_container.hpp>
  9. #include <ext/pb_ds/tree_policy.hpp>
  10.  
  11. using namespace std;
  12. using namespace __gnu_pbds;
  13.  
  14. // ===================== FAST IO / DEBUG =====================
  15. #ifndef ONLINE_JUDGE
  16. #define debug(x) cerr << #x << " = " << x << '\n';
  17. #define iosystem freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);
  18. #else
  19. #define debug(x)
  20. #define iosystem
  21. #endif
  22.  
  23. #define fastio ios::sync_with_stdio(false); cin.tie(nullptr);
  24.  
  25. // ===================== OPTIMIZATION =====================
  26. #pragma GCC optimize("O3,unroll-loops")
  27. #pragma GCC target("avx2,popcnt")
  28.  
  29. // ===================== TYPES =====================
  30. using ll = long long;
  31. using vi = vector<int>;
  32. using vll = vector<ll>;
  33. using pii = pair<int,int>;
  34. using vpii = vector<pii>;
  35.  
  36. // ===================== CONSTANTS =====================
  37. const ll mod = 1e9 + 7;
  38. const ll INF = LLONG_MAX;
  39. const double PI = acos(-1.0);
  40.  
  41. // ===================== CUSTOM HASH =====================
  42. struct custom_hash {
  43. static uint64_t splitmix64(uint64_t x){
  44. x += 0x9e3779b97f4a7c15;
  45. x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
  46. x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
  47. return x ^ (x >> 31);
  48. }
  49.  
  50. size_t operator()(uint64_t x) const {
  51. static const uint64_t FIXED_RANDOM =
  52. chrono::steady_clock::now().time_since_epoch().count();
  53. return splitmix64(x + FIXED_RANDOM);
  54. }
  55.  
  56. template<class T, class U>
  57. size_t operator()(const pair<T,U>& p) const {
  58. static const uint64_t FIXED_RANDOM =
  59. chrono::steady_clock::now().time_since_epoch().count();
  60. return splitmix64(hash<T>{}(p.first) + FIXED_RANDOM)
  61. ^ (splitmix64(hash<U>{}(p.second) + FIXED_RANDOM) << 1);
  62. }
  63. };
  64.  
  65. // ===================== PBDS =====================
  66. template<class T>
  67. using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  68.  
  69. template<class T>
  70. using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
  71.  
  72. // order_of_key, find_by_order
  73.  
  74. template<class T>
  75. void safe_erase(ordered_multiset<T>& s, const T& val){
  76. int idx = s.order_of_key(val);
  77. auto it = s.find_by_order(idx);
  78. if(it != s.end() && *it == val) s.erase(it);
  79. }
  80.  
  81. // ===================== LOGIC HELPERS =====================
  82. //
  83.  
  84. //
  85.  
  86.  
  87. #define int long long
  88. // order_of_key, find_by_order
  89. // ===================== SOLVE =====================
  90. bool multicases = false;
  91.  
  92. void solve(){
  93.  
  94.  
  95. int n;cin>>n;
  96. string a;cin>>a;
  97. string b;cin>>b;
  98.  
  99. int idx=-1;
  100. for(int i = 0 ; i < n ; i++){
  101. if(a[i]<=b[i]){
  102. idx=i;
  103. break;
  104. }
  105. }
  106.  
  107. if(idx==-1) idx=0;//if all are larger
  108.  
  109. bool found=false;
  110.  
  111. for(int i = 0 ; i < n; i ++){
  112. if(i==idx) continue;
  113. swap(a[i],a[idx]);
  114. swap(b[i],b[idx]);
  115.  
  116. if(a>b){
  117. cout<<"YES\n"<<min(idx,i)+1<<' '<<max(idx,i)+1;//1-indexed
  118. found=true;
  119. break;
  120. }
  121.  
  122. swap(a[i],a[idx]);
  123. swap(b[i],b[idx]);
  124. }
  125.  
  126. if(!found) cout<<"NO\n";
  127.  
  128.  
  129. }
  130. // order_of_key, find_by_order
  131.  
  132.  
  133. // ===================== MAIN =====================
  134. signed main(){
  135. cin.exceptions(cin.failbit);
  136. //if wrong in thing which usually fails silently it makes rutime error
  137. //instead of wrong answer to know that problem may be not in the logic
  138.  
  139. fastio;
  140. iosystem;//<<<<<<<<<<<
  141.  
  142. int T = 1;
  143. if(multicases) cin >> T;
  144.  
  145. while(T--) solve();
  146.  
  147. return 0;
  148. }
Success #stdin #stdout 0s 5316KB
stdin
3
abc
abc
stdout
NO