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
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<complex>
#include<map>
#include<iomanip>
#include<sstream>
#include<queue>
#include<set>
#include<string>
#include<vector>
#include<iostream>
#include<cstring>
#include<stack>
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define fup FOR
#define fdo FORD
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define siz SZ
#define CLR(x) memset((x), 0, sizeof(x))
#define PB push_back
#define MP make_pair
#define X first
#define Y second 
#define FI X
#define SE Y
#define SQR(a) ((a)*(a))
#define DEBUG 1
#define debug(x) {if (DEBUG)cerr <<#x <<" = " <<x <<endl; }
#define debugv(x) {if (DEBUG) {cerr <<#x <<" = "; FORE(it, (x)) cerr <<*it <<", "; cout <<endl; }}
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int>P;
typedef vector<int>VI;
const int INF=1E9+7;
template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }

#include "message.h"

#ifdef MY_OWN_COMPUTER
void PutInt(int a, int b) {}
int GetInt(int a, int b) {}
int Receive(int) {}
int GetInt(int) {}
void Send(int) {}
int NumberOfNodes() { return 1;}
int MyNodeId() { return 0;}
#endif

const int MAX = 100*1000+15;
LL MAX_STEPS = 950;
LL n,m, NoN;
char s[MAX], t[MAX];

P processed_collumn[2][MAX];
P bottom_row[MAX];
P top_row[MAX];

void receive_row(int from, int s1, int s2) {
	if (from>=0) {
		Receive(from);
		FOR(i,s1,s2) {
			bottom_row[i].FI = GetInt(from);
			bottom_row[i].SE = GetInt(from);
		}
	} else {
		FOR(i,s1,s2) {
			bottom_row[i].FI = i;
			bottom_row[i].SE = 0;
		}
	}
}

void send_row(int to, int s1, int s2) {
	if (to<NoN) {
		FOR(i,s1,s2) {
			PutInt(to, top_row[i].FI);
			PutInt(to, top_row[i].SE);
		}
		Send(to);
	}
}

int _t1, _t2, _s1, _s2;

void store(int i, int j, P p) {
	processed_collumn[i&1][j] = p;
	if (j==_t2)
		top_row[i] = p;
}

P retr(int i, int j) {
	if (j<_t1) {
		if (i==0)
			return processed_collumn[0][j];
		else
			return bottom_row[i];
	} else
		return processed_collumn[i&1][j];
}

P minD(P del, P ins, P subs, bool penalty) {
	P p[3] = {del, ins, subs};
	if (penalty) p[2].SE++;
	sort(&p[0], &p[3]);
	p[0].FI++;
	return p[0];
}

void calc_block(int s1, int s2, int t1, int t2){
	_s1 = s1; _t1=t1; _s2=s2; _t2=t2;
	FOR(i,s1,s2) {
		FOR(j,t1,t2) {
			if (s[i]==t[j]) {				
				store(i,j, retr(i-1, j-1));
			} else {
				store(i,j, minD(retr(i-1,j), retr(i, j-1), retr(i-1,j-1), s[i]<t[j]));
			}
		}
	} 
}

int main(){
	ios_base::sync_with_stdio(false);
	cout << setprecision(15) << fixed;
	cin>>n>>m>>&s[1]>>&t[1];
	int myN = MyNodeId();
	NoN = min((int)m/10+1,NumberOfNodes());
	//NoN = NumberOfNodes();
	if (MyNodeId()>=NoN) return 0;
	FOR(i,1,m) processed_collumn[0][i].FI = i;

	MAX_STEPS = min(n/10+1, 950LL);

	FOR(i, 0, MAX_STEPS-1) {
	//	if (myN==0) cerr<<i<<'/'<<(MAX_STEPS-1)<<'\r';
		int s1 = n*i/MAX_STEPS+1;
		int s2 = n*(i+1)/MAX_STEPS;
		int t1 = m*myN/NoN+1;
		int t2 = m*(myN+1)/NoN;
		receive_row(myN-1, s1, s2);
		calc_block(s1, s2, t1, t2);
		send_row(myN+1, s1, s2);
	}
	if (MyNodeId()==NoN-1) {
		cout<<retr(n,m).FI<<' '<<retr(n,m).SE<<endl;
	}
	return 0;
}