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
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#include "message.h"

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<tr1/unordered_map>
#include<queue>
#include<cstdlib>
#include<list>
#include<set>
#include<map>
#include<cmath>
#define MP make_pair
#define PB push_back
#define s second
#define f first
#define PII pair<int,int>
#define VPII vector <pair<int,int> >
#define VI vector <int>
#define abs(a) max((a),-(a))
#define LL long long
#define LD long double
#define ALL(x) x.begin(),x.end()
#define PU putchar_unlocked
#define GU getchar_unlocked
#define DBG(x) cerr<<#x<<" "<<(x)<<endl;
using namespace std;
int a,b,c,d,e,f,n,m,mx,l,r,k;
int wynik;
char ch;
int INF=1e9+1;
const int MXN=1e5+4;
int ID;
int P;
int MESS=400;

char c1[MXN];
char c2[MXN];

int poc,kon;

PII kol[MXN];
PII lastkol[MXN];

PII wie[2][MXN];

int C1,C2;

void licz(int i,int j)
{
//printf("a %d %d ",i,j);
j=j-poc+1;

wie[i&1][j]=min(MP(wie[(i-1)&1][j].f+1,wie[(i-1)&1][j].s),MP(wie[i&1][j-1].f+1,wie[i&1][j-1].s));

if(c1[i-1]==c2[j+poc-2])
    {//printf("aa %d %d",c1[i-1],c2[j+poc-2]);
    wie[i&1][j]=min(wie[i&1][j],wie[(i-1)&1][j-1]);
    }

if(c1[i-1]<c2[j+poc-2])
    {
    wie[i&1][j]=min(wie[i&1][j],MP(wie[(i-1)&1][j-1].f+1,wie[(i-1)&1][j-1].s+C1));
    }
if(c1[i-1]>c2[j+poc-2])
    {
    wie[i&1][j]=min(wie[i&1][j],MP(wie[(i-1)&1][j-1].f+1,wie[(i-1)&1][j-1].s+C2));
    }
//printf("w %d %d\n",wie[i%2][j].f,wie[i%2][j].s);

}
void solve()
{
scanf("%d%d",&n,&m);//n to liczba wierszy
scanf("%s",c1);
scanf("%s",c2);
C1=1;
C2=0;
/*
if(n<m)
    {
    swap(C1,C2);
    swap(n,m);
    swap(c1,c2);
    }
*/
ID=MyNodeId();
P=NumberOfNodes();

VI momentywyslania;//wysyłam po, odbieram przed
int co=n/(MESS);
if(n%(MESS)>0)co++;

int ter=0;
while(ter<n)
    {
    momentywyslania.PB(ter);
    ter+=co;
    }
momentywyslania.PB(n);
int w1=0,w2=1;

int siz=m/P;
if(m%P)siz++;
poc=1+ID*siz;
kon=min(m,poc+siz-1);


if(poc>kon)return;

kol[0]=MP(poc-1,0);
if(ID==0)
    {
    for(int i=1;i<=n;i++)
        {
        kol[i]=MP(max(0,i),0);
        }
    }
//for(int i=poc-1;

wie[0][0]=kol[0];
for(int i=poc-1;i<=kon;i++)
    {
    wie[0][i-poc+1]=MP(max(0,i),0);
 //  printf(" %d %d w %d %d\n",0,i,wie[0][i-poc+1].f,wie[0][i-poc+1].s);
    }

//printf("ID %d poc %d kon %d\n",ID,poc,kon);


for(int i=1;i<=n;i++)
    {
//    printf("ID %d i %d\n",ID,i);
    if(ID!=0&&momentywyslania[w1]+1==i)
        {
        Receive(ID-1);
        for(int j=momentywyslania[w1]+1;j<=momentywyslania[w1+1];j++)
            {
   //          printf("czytam %d\n",j);
            kol[j].f=GetInt(ID-1);
            kol[j].s=GetInt(ID-1);
            }
        w1++;
        }
    wie[i&1][0]=kol[i];
//    printf(" %d %d w %d %d\n",i,0,wie[i%2][0].f,wie[i%2][0].s);
    
    for(int j=poc;j<=kon;j++)
        {
        licz(i,j);        
        }
    lastkol[i]=wie[i&1][kon-poc+1];
    
    if(kon!=m&&momentywyslania[w2]==i)
        {
        
        for(int j=momentywyslania[w2-1]+1;j<=momentywyslania[w2];j++)
            {
//            printf("sle %d\n",j);
            PutInt(ID+1,lastkol[j].f);
            PutInt(ID+1,lastkol[j].s);
            }
        w2++;
        Send(ID+1);
        }
    }
if(kon==m)
    {
    printf("%d %d\n",lastkol[n].f,lastkol[n].s);
    }

}
main()
{
solve();
}