//Krzysztof Kleiner #include<iostream> #include<cstdio> #include<algorithm> #define FOR(i, b, n) for ( int (i) = b; (i) < (n); (i)++) #define FORR(i, b, n) for ( (i) = b; (i) < (n); (i)++) #define REP(i, n) for ( int (i) = 0; (i) < (n); (i)++) #define SC(n) scanf("%d", &(n)) #define SC2(n, m) scanf("%d%d", &(n), &(m)) #define SCLL(n) scanf("%lld", &(n)) #define PRT(n) printf("%d ", (n)) #define PRTLL(n) printf("%lld ", (n)) #define NXL printf("\n") typedef long long LL; typedef unsigned long long ULL; using namespace std; #include<set> #include<map> #include<vector> #include<stack> #include<cstring> #include "message.h" const int MANY = 100010; //////////////////////////////////// /******** ** ** **/ struct str { int p, sh; str(int p, int sh) : p(p), sh(sh){} str(){} }; bool operator < (str x, str y) { if(x.p != y.p) return x.p < y.p; return x.sh < y.sh; } str a[MANY][2]; char s[MANY], t[MANY]; int main() { int n, m; SC2(n, m); scanf("%s", s+1); scanf("%s", t+1); int nodes = NumberOfNodes(); int me = MyNodeId(); int mstep = m/1000 + 1; int nstep = n/nodes + 1; int nstart = 1 + nstep*me; if(nstart > n) return 0; int nstop = nstart + nstep; // 1 after nstop = min(nstop, n+1); FOR(i, max(nstart - 1, 0), nstop) { a[i][0].p = i; a[i][0].sh = 0; } FOR(j, 1, m+1) { if(me == 0) { a[0][j&1].p = j; a[0][j&1].sh = 0; } else { if((j-1) % mstep == 0) Receive(me - 1); a[nstart-1][j&1].p = GetInt(me - 1); a[nstart-1][j&1].sh = GetInt(me - 1); } FOR(i, nstart, nstop) { str ch; if(s[i] != t[j]) { ch.p = a[i-1][(j+1)&1].p + 1; ch.sh = a[i-1][(j+1)&1].sh + (s[i] < t[j]) ; } else { ch.p = a[i-1][(j+1)&1].p; ch.sh = a[i-1][(j+1)&1].sh; } str dl ( a[i-1][j&1].p + 1, a[i-1][j&1].sh); str ad ( a[i][(j+1)&1].p + 1, a[i][(j+1)&1].sh); a[i][j&1] = min(ch, min(dl, ad)); // printf("node %d liczy %d,%d: %d %d\n", me, i, j, a[i][j].p, a[i][j].sh); } if(nstop != n+1) { PutInt(me + 1, a[nstop-1][j&1].p); PutInt(me + 1, a[nstop-1][j&1].sh); } if((nstop != n+1) && (j % mstep == 0 || j == m)) { Send(me + 1); } } if(nstop == n+1) { PRT(a[n][m&1].p); PRT(a[n][m&1].sh); NXL; } }
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 | //Krzysztof Kleiner #include<iostream> #include<cstdio> #include<algorithm> #define FOR(i, b, n) for ( int (i) = b; (i) < (n); (i)++) #define FORR(i, b, n) for ( (i) = b; (i) < (n); (i)++) #define REP(i, n) for ( int (i) = 0; (i) < (n); (i)++) #define SC(n) scanf("%d", &(n)) #define SC2(n, m) scanf("%d%d", &(n), &(m)) #define SCLL(n) scanf("%lld", &(n)) #define PRT(n) printf("%d ", (n)) #define PRTLL(n) printf("%lld ", (n)) #define NXL printf("\n") typedef long long LL; typedef unsigned long long ULL; using namespace std; #include<set> #include<map> #include<vector> #include<stack> #include<cstring> #include "message.h" const int MANY = 100010; //////////////////////////////////// /******** ** ** **/ struct str { int p, sh; str(int p, int sh) : p(p), sh(sh){} str(){} }; bool operator < (str x, str y) { if(x.p != y.p) return x.p < y.p; return x.sh < y.sh; } str a[MANY][2]; char s[MANY], t[MANY]; int main() { int n, m; SC2(n, m); scanf("%s", s+1); scanf("%s", t+1); int nodes = NumberOfNodes(); int me = MyNodeId(); int mstep = m/1000 + 1; int nstep = n/nodes + 1; int nstart = 1 + nstep*me; if(nstart > n) return 0; int nstop = nstart + nstep; // 1 after nstop = min(nstop, n+1); FOR(i, max(nstart - 1, 0), nstop) { a[i][0].p = i; a[i][0].sh = 0; } FOR(j, 1, m+1) { if(me == 0) { a[0][j&1].p = j; a[0][j&1].sh = 0; } else { if((j-1) % mstep == 0) Receive(me - 1); a[nstart-1][j&1].p = GetInt(me - 1); a[nstart-1][j&1].sh = GetInt(me - 1); } FOR(i, nstart, nstop) { str ch; if(s[i] != t[j]) { ch.p = a[i-1][(j+1)&1].p + 1; ch.sh = a[i-1][(j+1)&1].sh + (s[i] < t[j]) ; } else { ch.p = a[i-1][(j+1)&1].p; ch.sh = a[i-1][(j+1)&1].sh; } str dl ( a[i-1][j&1].p + 1, a[i-1][j&1].sh); str ad ( a[i][(j+1)&1].p + 1, a[i][(j+1)&1].sh); a[i][j&1] = min(ch, min(dl, ad)); // printf("node %d liczy %d,%d: %d %d\n", me, i, j, a[i][j].p, a[i][j].sh); } if(nstop != n+1) { PutInt(me + 1, a[nstop-1][j&1].p); PutInt(me + 1, a[nstop-1][j&1].sh); } if((nstop != n+1) && (j % mstep == 0 || j == m)) { Send(me + 1); } } if(nstop == n+1) { PRT(a[n][m&1].p); PRT(a[n][m&1].sh); NXL; } } |