Submission #38318

# Submission time Handle Problem Language Result Execution time Memory
38318 2018-01-03T16:48:32 Z b00n0rp Retro (COCI17_retro) C++14
0 / 100
3 ms 10064 KB
/*input
3 3
ABC
CDE
*/		
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define int ll
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(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 all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

int power(int a,int b,int m = MOD){
	if(b == 0) return 1;
	if(b == 1) return a;
	int x = power(a,b/2,m)%m;
	x = (x*x)%m;
	if(b%2) return (x*a)%m;
	return x;
}

int n,m;
string a,b;
int dp[1005][1005];

void solve(){
	cin >> n >> m >> a >> b;
	REP(i,1005) REP(j,1005) dp[i][j] = 0;
	for(int i = n-1; i >= 0; i--){
		for(int j = m-1; j >= 0; j--){
			if(a[i]==b[j]) dp[i][j] = 1+dp[i+1][j+1];
			else dp[i][j] = min(dp[i+1][j],dp[i][j+1]);
		}
	}
	int x = 0,y = 0;
	while(x < n or y < m){
		if(x == n) cout << b[y++];
		else if(y == m) cout << a[x++];
		else if(a[x] == b[y]){
			cout << a[x];
			x ++;
			y ++;
		}
		else if(dp[x+1][y] == dp[x][y+1]){
			if(a[x] < b[y]) cout << a[x++];
			else cout << b[y++];
		}
		else if(dp[x+1][y] < dp[x][y+1]) cout << a[x++];
		else cout << b[y++];
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	// cin >> t;
	WL(t) solve();
}

# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 10064 KB Expected integer, but "...).)*.*...).." found
2 Incorrect 3 ms 10064 KB Expected integer, but "..(..(..(.).()).()..**..*...(.(*(" found
3 Incorrect 0 ms 10064 KB Expected integer, but "..(.(..((((" found
4 Incorrect 0 ms 10064 KB Expected integer, but ".)*...)(.(...(.)*.(.)(*..(..(.)....(.*.)" found
5 Incorrect 0 ms 10064 KB Expected integer, but ".......(*.....(.()...)(..).((......(....).........))).*).)*....." found
6 Incorrect 3 ms 10064 KB Expected integer, but "..).).*........).(....................*...(*...)..*.))...(.(..*)" found
7 Incorrect 0 ms 10064 KB Expected integer, but ")((..)....)..(***(.)(..)....)*.....).(.()...)..*.........(..(..." found
8 Incorrect 0 ms 10064 KB Expected integer, but "..(.(.............*.(...*......(..." found
9 Incorrect 0 ms 10064 KB Expected integer, but ".........)......(..*........*....(..)(......)...........*......." found
10 Incorrect 3 ms 10064 KB Expected integer, but "..........)........)..................(..).*.).*)........(.....*" found
11 Incorrect 3 ms 10064 KB Expected integer, but "..).(*..)..)...)......**(....*....(..*..)...(*..)........*..).)." found
12 Incorrect 3 ms 10064 KB Expected integer, but "..()...*)*...*.....*.()...).........*...*...*.(.)*..*(..*.*...*." found
13 Incorrect 0 ms 10064 KB Expected integer, but ".......(.....).(.............*.....*........(..*.*..*..........." found
14 Incorrect 0 ms 10064 KB Expected integer, but "...*..**........*...**).*..........)**(.............(....*.(...." found
15 Incorrect 3 ms 10064 KB Expected integer, but "...)......(......).......(*......*....(.......)..*.(..)....(*..." found
16 Incorrect 0 ms 10064 KB Expected integer, but "....(..(......*...*....*.(.(.*....)...*.......)*....()(..(......" found
17 Incorrect 0 ms 10064 KB Expected integer, but "..........)(...*).....*...(.)*...........(....(........)...)..*(" found
18 Incorrect 0 ms 10064 KB Expected integer, but "..*.....)(.)*....*..(.*.....(......*..*..(.**.*...*........*...." found
19 Incorrect 0 ms 10064 KB Expected integer, but "...(.(....())..)*....)(*.).................*..*.......)..(......" found
20 Incorrect 3 ms 10064 KB Expected integer, but ".)..*...(*...(..()..........*.....*....*........(..)....*..().*)" found