-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvstr.cpp
More file actions
86 lines (72 loc) · 1.46 KB
/
convstr.cpp
File metadata and controls
86 lines (72 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define mod 1000000007
#define int long long int
#define pb push_back
#define mk make_pair
#define flp(i, k, n) for(int i=k; i<n; i++)
#define rev(i, k) for(int i=k; i>=0; i--)
#define F first
#define S second
#define pi pair<int, int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define SIZE (int)(6e5)
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
void solve()
{
int n; cin>>n;
string a, b; cin>>a>>b;
vector< vector<int> > ans;
flp(i, 0, n)
{
if(a[i]<b[i])
{
cout<<-1<<"\n";
return;
}
}
for(char c='z'; c>='a'; c--)
{
vector<int> pos;
bool f=false;
flp(i, 0, n)
{
if(b[i]==c && a[i]!=b[i])
pos.pb(i);
}
if(!f && !pos.empty())
{
flp(i, 0, n)
{
if(a[i]==c)
{
f=true;
pos.pb(i);
}
}
}
if(!f && !pos.empty())
{
cout<<-1<<"\n";
return;
}
if(!pos.empty()) ans.pb(pos);
for(int i:pos) a[i]=c;
}
cout<<ans.size()<<"\n";
for(auto x:ans)
{
cout<<x.size()<<" ";
for(auto y:x) cout<<y<<" ";
cout<<"\n";
}
}
int32_t main(void)
{
int t;
cin>>t;
while(t--) solve();
return 0;
}