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
#include<iostream>
#include<vector>
#include "message.h"

#define PUII std::pair<unsigned int, unsigned int>
#define VECPUII std::vector<PUII >
#define VV std::vector<VECPUII >

const unsigned int segment=99;

struct Compare{
	bool mniejszy;
	Compare(bool x=true):mniejszy(x) {}
	bool operator() (char a, char b) const{
		if(mniejszy) return (a<b);
		else return(a>b);
	}
};

int main(){
	std::ios_base::sync_with_stdio(false);
	
	unsigned int n,m;
	std::cin>>n>>m;
	
	std::string a,b;
	std::cin>>a>>b;
	
	Compare Porownaj;
	if(m<n)
		std::swap(n,m),std::swap(a,b),Porownaj.mniejszy=false;
		
	unsigned int poczatek=(n/NumberOfNodes())*MyNodeId();
	unsigned int liczba=(n/NumberOfNodes());
	if(MyNodeId()+1==NumberOfNodes())
		liczba=n-poczatek;
	
	VV Tab(liczba+1, VECPUII(segment+1,PUII(0,0)));
	
	for(unsigned int t=0;t<m;t+=segment){
		int source;
		if(MyNodeId()){
			source=Receive(MyNodeId()-1);
			for(unsigned int k=t;(k-t)<=segment&&k<=m;++k){
				Tab[0][k-t].first=GetInt(source);
				Tab[0][k-t].second=GetInt(source);
			}
		}
		for(unsigned int i=1;i<=liczba;++i)
			for(unsigned int j=1;j<=segment&&j+t<=m;++j){
				PUII c= PUII(Tab[i-1][j-1].first+(a[poczatek+i-1]==b[t+j-1]),
						Tab[i-1][j-1].second+(Porownaj(b[t+j-1],a[poczatek+i-1])));
				Tab[i][j]=std::max(Tab[i][j-1],c);
			}
		if((source=MyNodeId()+1)!=NumberOfNodes()){
			for(unsigned int k=t;(k-t)<=segment&&k<=m;++k){
				PutInt(source,Tab[liczba][k-t].first);
				PutInt(source,Tab[liczba][k-t].second);
			}
			Send(source);
		}
		for(unsigned int i=1;i<=liczba;++i)
			Tab[i][0]=Tab[i][segment];
	}
	
	if(MyNodeId()+1==NumberOfNodes()){
		unsigned int p=Tab[liczba][(m-1)%segment+1].first,q=Tab[liczba][(m-1)%segment+1].second;
		std::cout<<(m-p)<<" "<<(n-p-q)<<std::endl;
	}
	
	return 0;
}