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
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include "message.h"
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

int id, nodesnumber;
int d, pocz, kon;
pii dp[100042][2];
pii ukos;

/*pii mini(pii a, pii b, pii c)
{
    vector<pii> v;
    v.pb(a); v.pb(b); v.pb(c);
    sort(v.begin(),v.end());
    return v[0];
}*/

int update(int i,int j, pii a, pii b, pii c)
{
    vector<pii> v;
    v.pb(a); v.pb(b); v.pb(c);
    sort(v.begin(),v.end());
    dp[i][j%2]=v[0];
    //printf("dp[%d][%d]= %d %d\n",i,j,dp[i][j%2].first,dp[i][j%2].second);
    return 0;
}

int main()
{
    //IOS
    id = MyNodeId();
    nodesnumber = NumberOfNodes();
    wez2(n,m);
    string a,b;
    cin>>a>>b;
    d = max(1,m/900);
    //if(id==0)printf("d = %d\n",d);
    
    pocz = max(1,id*(n/nodesnumber));
    kon = min(n,(id+1)*(n/nodesnumber)-1);
    if(id == nodesnumber-1)kon=n;
    
    //printf("id: %d pocz %d kon %d\n",id,pocz,kon);
    ukos = mp(pocz-1,0);
    //printf("liczba inst %d\n",nodesnumber);
    //printf("moje id %d\n",id);
    for(int i=0;i<=n;i++)dp[i][0]=mp(i,0);
    dp[0][1]=mp(1,0);
    for(int begin=1; begin<=m; begin+=d)
    {
    	//printf("%d ",id);
    	if(id != 0)Receive(id-1);
    	int end = min(m,begin+d-1);
    	for(int j=begin;j<=end;j++)
    	{
    		dp[0][j%2]=mp(j,0);
    		
    		int f,s;
    		if(id != 0)
    		{
    			f = GetInt(id-1); s = GetInt(id-1);
    			//printf("Odebralem %d %d\n",f,s);
    		}
    		for(int i=pocz; i<=kon;i++)
    		{
    			pii up, left, upleft;
    			if(i==pocz)upleft = ukos;
    			else upleft = dp[i-1][(j-1)%2];
    			
    			if(i==pocz && id != 0)up=mp(f,s);
    			else up = dp[i-1][j%2];
    			
    			left = dp[i][(j-1)%2];
    			
    			/*if(i==9 && j==6)
    			{
    				printf("------------9 6\n");
    				printf("up %d %d\n",up.first,up.second);
    				printf("left %d %d\n",left.first,left.second);
    				printf("upleft %d %d\n",upleft.first,upleft.second);
    				//printf("3 2\n");
    				//printf("dp[
    			}*/
    			
   			if(a[i-1] == b[j-1])
   			{
   				//if(i==2 && j==1)printf("          hura\n");
   				update(i,j,upleft,mp(left.first+1,left.second),mp(up.first+1,up.second));  			
   			}
   			else if((int)a[i-1]>(int)b[j-1])
   			{
   				update(i,j,mp(left.first+1,left.second),mp(up.first+1,up.second),mp(upleft.first+1,upleft.second));
   			}
   			else
   			{
   				update(i,j,mp(left.first+1,left.second),mp(up.first+1,up.second),mp(upleft.first+1,upleft.second+1));
   			}
    		}
    		if(id != 0)ukos = mp(f,s);
    		else ukos = mp(j,0);
    		if(id != nodesnumber-1 )
    		{
    			//printf("Wysylam %d %d\n",dp[kon][j%2].first,dp[kon][j%2].second);
    			PutInt(id+1,dp[kon][j%2].first);
    			PutInt(id+1,dp[kon][j%2].second);
    		}
    	}
    	if( id != nodesnumber-1)Send(id+1);
    }
    if(id == nodesnumber-1)
    {
 	printf("%d %d\n",dp[n][m%2].first,dp[n][m%2].second);   	
    }
    return 0;   
}