正文
增加 17 行删除 17 行
94 行未改动959697989910010110210311 行未改动1151161171181191201211221232 行未改动12612712812913013113213313413513613713813914014114214326 行未改动1701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162174 行未改动222223224225226227228229230231232233234235236237238239240241242243244245246247248249102 行未改动全部展开3523533543553563573583593603613623633643653663673683697 行未改动94 行未改动ans.push_back({0,tot});ttt[ttt.size()-1]+=s.top(),s.pop();reverse(ttt.begin(),ttt.end());for(auto id:ttt) s.push(id);ffor(i,1,tc/2-1) {int a1=s.top(),b1=t.top();s.pop(),t.pop();int b2=s.top(),a2=t.top();11 行未改动t.push(a1+a3);s.push(b2),s.push(a2);sc=2,tc-=2;solve(sc,tc);return ;}if(tc==1) {if(sc%4==2) {vector<int> ttt;2 行未改动ans.push_back({tot,0});ttt[ttt.size()-1]+=t.top(),t.pop();reverse(ttt.begin(),ttt.end());for(auto id:ttt) t.push(id);ffor(i,1,sc/2-1) {int a1=s.top(),b1=t.top();s.pop(),t.pop();int b2=s.top(),a2=t.top();s.pop(),t.pop();ans.push_back({a1,b1});s.push(b1+b2),t.push(a1+a2);}return ;}int a1=t.top(); t.pop();int a2=s.top(); s.pop();int b2=s.top(); s.pop();26 行未改动ans.push_back({a2+b2,a1});t.push(b1+b2),t.push(a2);s.push(a1+a3);solve(sc-2,tc);return ;}}int main() {ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);cin>>S>>T,n=S.size(),m=T.size(),S="&"+S,T="&"+T;int len=1;roff(i,n-1,1) if(S[i]==S[i+1]) len++;else s.push(len),len=1,sc++;s.push(len),len=1,sc++;roff(i,m-1,1) if(T[i]==T[i+1]) len++;else t.push(len),len=1,tc++;t.push(len),len=1,tc++;if(S[1]==T[1]) {solve(sc,tc);cout<<ans.size()<<'\n';for(auto pr:ans) cout<<pr.first<<' '<<pr.second<<'\n';return 0;}if(sc==tc&&sc==1) return cout<<0,0;if(sc==1&&tc==2) {int a=s.top(),b=t.top();cout<<1<<'\n'<<a<<' '<<b;return 0;}if(sc==2&&tc==1) {int b=s.top(),a=t.top();cout<<1<<'\n'<<b<<' '<<a;return 0;}if(sc==1&&tc==3) {int a1=s.top();int b1=t.top(); t.pop();int a2=t.top(); t.pop();int b2=t.top(); t.pop();cout<<2<<'\n'<<a1<<' '<<b1<<'\n'<<b1<<' '<<a1+a2;return 0;}if(sc==3&&tc==1) {int a1=t.top();int b1=s.top(); s.pop();4 行未改动}if(sc==2&&tc==3) {int a1=s.top(),b1=t.top();s.pop(),t.pop();int b2=s.top(),a2=t.top();s.pop(),t.pop();int b3=t.top();cout<<2<<'\n'<<a1<<' '<<b1<<'\n'<<b1+b2<<' '<<a1+a2<<'\n';return 0;}if(sc==3&&tc==2) {int a1=t.top(),b1=s.top();t.pop(),s.pop();int b2=t.top(),a2=s.top();t.pop(),s.pop();int b3=s.top();cout<<2<<'\n'<<b1<<' '<<a1<<'\n'<<a1+a2<<' '<<b1+b2<<'\n';return 0;}if((sc+tc)%2==1) {int hf=(sc+tc-1)/2;if((max(sc,tc)-min(sc,tc))%4==1) {vector<int> ss,tt;if(sc<=tc) {int c1=0,c2=0;ffor(i,1,sc) c1+=s.top(),ss.push_back(s.top()),s.pop();ffor(i,1,hf) c2+=t.top(),tt.push_back(t.top()),t.pop();ss[ss.size()-1]+=t.top(),t.pop();102 行未改动全部展开int a2=t.top(); t.pop();ans.push_back({0,b1+a2});s.push(a1+a2),s.push(b1);sc++,tc-=2;solve(sc,tc);}else {int a1=t.top(),b1=s.top();s.pop(),t.pop();int a2=s.top(); s.pop();ans.push_back({b1+a2,0});t.push(a1+a2),t.push(b1);tc++,sc-=2;solve(sc,tc);}cout<<ans.size()<<'\n';for(auto pr:ans) cout<<pr.first<<' '<<pr.second<<'\n';return 0;7 行未改动94 行未改动959697989910010110210311 行未改动1151161171181191201211221232 行未改动12612712812913013113213313413513613713813914014114214326 行未改动1701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162174 行未改动222223224225226227228229230231232233234235236237238239240241242243244245246247248249102 行未改动全部展开3523533543553563573583593603613623633643653663673683697 行未改动94 行未改动ans.push_back({0,tot});ttt[ttt.size()-1]+=s.top(),s.pop();reverse(ttt.begin(),ttt.end());for(auto id:ttt) s.push(id);ffor(i,1,tc/2-1) {int a1=s.top(),b1=t.top();s.pop(),t.pop();int b2=s.top(),a2=t.top();11 行未改动t.push(a1+a3);s.push(b2),s.push(a2);sc=2,tc-=2;solve(sc,tc);return ;}if(tc==1) {if(sc%4==2) {vector<int> ttt;2 行未改动ans.push_back({tot,0});ttt[ttt.size()-1]+=t.top(),t.pop();reverse(ttt.begin(),ttt.end());for(auto id:ttt) t.push(id);ffor(i,1,sc/2-1) {int a1=s.top(),b1=t.top();s.pop(),t.pop();int b2=s.top(),a2=t.top();s.pop(),t.pop();ans.push_back({a1,b1});s.push(b1+b2),t.push(a1+a2);}return ;}int a1=t.top(); t.pop();int a2=s.top(); s.pop();int b2=s.top(); s.pop();26 行未改动ans.push_back({a2+b2,a1});t.push(b1+b2),t.push(a2);s.push(a1+a3);solve(sc-2,tc);return ;}}int main() {ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);cin>>S>>T,n=S.size(),m=T.size(),S="&"+S,T="&"+T;int len=1;roff(i,n-1,1) if(S[i]==S[i+1]) len++;else s.push(len),len=1,sc++;s.push(len),len=1,sc++;roff(i,m-1,1) if(T[i]==T[i+1]) len++;else t.push(len),len=1,tc++;t.push(len),len=1,tc++;if(S[1]==T[1]) {solve(sc,tc);cout<<ans.size()<<'\n';for(auto pr:ans) cout<<pr.first<<' '<<pr.second<<'\n';return 0;}if(sc==tc&&sc==1) return cout<<0,0;if(sc==1&&tc==2) {int a=s.top(),b=t.top();cout<<1<<'\n'<<a<<' '<<b;return 0;}if(sc==2&&tc==1) {int b=s.top(),a=t.top();cout<<1<<'\n'<<b<<' '<<a;return 0;}if(sc==1&&tc==3) {int a1=s.top();int b1=t.top(); t.pop();int a2=t.top(); t.pop();int b2=t.top(); t.pop();cout<<2<<'\n'<<a1<<' '<<b1<<'\n'<<b1<<' '<<a1+a2;return 0;}if(sc==3&&tc==1) {int a1=t.top();int b1=s.top(); s.pop();4 行未改动}if(sc==2&&tc==3) {int a1=s.top(),b1=t.top();s.pop(),t.pop();int b2=s.top(),a2=t.top();s.pop(),t.pop();int b3=t.top();cout<<2<<'\n'<<a1<<' '<<b1<<'\n'<<b1+b2<<' '<<a1+a2<<'\n';return 0;}if(sc==3&&tc==2) {int a1=t.top(),b1=s.top();t.pop(),s.pop();int b2=t.top(),a2=s.top();t.pop(),s.pop();int b3=s.top();cout<<2<<'\n'<<b1<<' '<<a1<<'\n'<<a1+a2<<' '<<b1+b2<<'\n';return 0;}if((sc+tc)%2==1) {int hf=(sc+tc-1)/2;if((max(sc,tc)-min(sc,tc))%4==1) {vector<int> ss,tt;if(sc<=tc) {int c1=0,c2=0;ffor(i,1,sc) c1+=s.top(),ss.push_back(s.top()),s.pop();ffor(i,1,hf) c2+=t.top(),tt.push_back(t.top()),t.pop();ss[ss.size()-1]+=t.top(),t.pop();102 行未改动全部展开int a2=t.top(); t.pop();ans.push_back({0,b1+a2});s.push(a1+a2),s.push(b1);sc++,tc-=2;solve(sc,tc);}else {int a1=t.top(),b1=s.top();s.pop(),t.pop();int a2=s.top(); s.pop();ans.push_back({b1+a2,0});t.push(a1+a2),t.push(b1);tc++,sc-=2;solve(sc,tc);}cout<<ans.size()<<'\n';for(auto pr:ans) cout<<pr.first<<' '<<pr.second<<'\n';return 0;7 行未改动