QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115173#5414. Stop, Yesterday Please No MoreUrgantTeam#RE 0ms0kbC++236.3kb2023-06-24 19:44:192023-06-24 19:44:20

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-24 19:44:20]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-06-24 19:44:19]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long double ld;
typedef long long ll;

struct Step
{
	int typ, x, y;
};

int start[25][25], finish[25][25];
int shab[25][25][25];
int cnt_start[66], cnt_finish[66], cnt_shab[25][66];
pair <int, int> sizes[25];

int convert_char(char c)
{
	if ('a' <= c && c <= 'z') return c - 'a' + 1;
	if ('A' <= c && c <= 'Z') return 26 + c - 'A' + 1;
	if ('0' <= c && c <= '9') return 52 + c - '0' + 1;
	return 0;
}

void move_to(int startx, int starty, int finishx, int finishy, vector <Step> &ans)
{
	cout << "Move from (" << startx << ' ' << starty << ") to (" << finishx << ' ' << finishy << ")\n";
	while (startx < finishx)
	{
	 	ans.pb({-4, startx + 1, starty});
	 	swap(finish[startx][starty], finish[startx + 1][starty]);
	 	startx++;
	}
	while (starty < finishy)
	{
	 	ans.pb({-2, startx, starty + 1});
	 	swap(finish[startx][starty], finish[startx][starty + 1]);
	 	starty++;
	}

	while (startx > finishx)
	{
	 	ans.pb({-3, startx - 1, starty});
	 	swap(finish[startx][starty], finish[startx - 1][starty]);
	 	startx--;
	}
	while (starty > finishy)
	{
	 	ans.pb({-1, startx, starty - 1});
	 	swap(finish[startx][starty], finish[startx][starty - 1]);
	 	starty--;
	}
	return;
}

int main()
{
 	freopen("input.txt", "r", stdin);
 	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cin.tie(0);

	int n, m, k;
	cin >> n >> m >> k;

	for (int i = 1; i <= n; i++)
	{
	 	string s;
	 	cin >> s;
	 	for (int j = 1; j <= m; j++)
	 		start[i][j] = convert_char(s[j - 1]);
	}

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cnt_start[start[i][j]]++;

	for (int i = 1; i <= n; i++)
	{
	 	string s;
	 	cin >> s;
	 	for (int j = 1; j <= m; j++)
	 		finish[i][j] = convert_char(s[j - 1]);
	}

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cnt_finish[finish[i][j]]++;

	for (int rep = 1; rep <= k; rep++)
	{
	 	int small_n, small_m;
	 	cin >> small_n >> small_m;
	 	sizes[rep] = mp(small_n, small_m);

	 	for (int i = 1; i <= small_n; i++)
    	{
    	 	string s;
    	 	cin >> s;
    	 	for (int j = 1; j <= small_m; j++)
    	 		shab[rep][i][j] = convert_char(s[j - 1]);
    	}

    	for (int i = 1; i <= small_n; i++)
    		for (int j = 1; j <= small_m; j++)
    			cnt_shab[rep][shab[rep][i][j]]++;
	}

	for (int i = 1; i <= n; i++)
	{
	 	for (int j = 1; j <= m; j++) cout << start[i][j] << ' ';
	 	cout << '\n';
	}
	cout << '\n';

	for (int i = 1; i <= n; i++)
	{
	 	for (int j = 1; j <= m; j++) cout << finish[i][j] << ' ';
	 	cout << '\n';
	}
	cout << '\n';

	cout << "Zero: " << cnt_start[0] << '\n';
	for (int i = 1; i <= 62; i++) cout << cnt_start[i] << ' ';
	cout << '\n';
	cout << '\n';
	cout << "Zero: " << cnt_finish[0] << '\n';
	for (int i = 1; i <= 62; i++) cout << cnt_finish[i] << ' ';
	cout << '\n';
	cout << '\n';

	for (int rep = 1; rep <= k; rep++)
	{
	 	for (int i = 1; i <= sizes[rep].x; i++)
	 	{
	 	 	for (int j = 1; j <= sizes[rep].y; j++) cout << shab[rep][i][j] << ' ';
	 	 	cout << '\n';
	 	}
	 	cout << '\n';

	 	for (int i = 1; i <= 62; i++) cout << cnt_shab[rep][i] << ' ';
	 	cout << '\n';
	 	cout << '\n';
	}
	
	vector <Step> ans;
	while (true)
	{
	 	int num = 1;
	 	while (num <= k)
	 	{
	 	 	int sum = cnt_finish[0];
	 	 	for (int ch = 1; ch <= 62; ch++)
	 	 		sum += min(cnt_finish[ch], cnt_shab[num][ch]);
	 	 	cout << "Sum: " << sum << '\n';
	 	 	if (sum < sizes[num].x * sizes[num].y || sum == cnt_finish[0]) {num++; continue;}
	 	 	
	 	 	for (int i = 1; i <= sizes[num].x; i++)
	 	 		for (int j = 1; j <= sizes[num].y; j++)
	 	 		{
	 	 		 	int need = shab[num][i][j];

	 	 		 	int posx = 0, posy = 0;
	 	 			bool fnd = false;
	 	 			for (int i1 = 1; i1 <= n && !fnd; i1++)
	 	 				for (int j1 = 1; j1 <= m && !fnd; j1++)
	 	 				{
	 	 				 	if (i1 <= i && j1 <= j && mp(i1, j1) != mp(i, j)) continue;
	 	 				 	if (finish[i1][j1] == need) {posx = i1; posy = j1; fnd = true;}
	 	 				}
	 	 			if (posx == 0)
	 	 			{
	 	 			 	for (int i1 = 1; i1 <= n && !fnd; i1++)
        	 				for (int j1 = 1; j1 <= m && !fnd; j1++)
        	 				{
        	 				 	if (i1 <= i && j1 <= j && mp(i1, j1) != mp(i, j)) continue;
        	 				 	if (finish[i1][j1] == 0) {posx = i1; posy = j1; fnd = true;}
        	 				}
	 	 			}
	 	 			move_to(posx, posy, i, j, ans);
	 	 		}
	 	 	ans.pb({num, 1, 1});
	 	 	for (int i = 1; i <= sizes[num].x; i++)
	 	 		for (int j = 1; j <= sizes[num].y; j++)
	 	 		{
	 	 		 	cnt_finish[finish[i][j]]--;
	 	 		 	finish[i][j] = 0;
	 	 		 	cnt_finish[finish[i][j]]++;
	 	 		}

	 	 	for (int i = 1; i <= n; i++)
        	{
        	 	for (int j = 1; j <= m; j++) cout << finish[i][j] << ' ';
        	 	cout << '\n';
        	}
        	cout << '\n';

        	cout << "Zero: " << cnt_finish[0] << '\n';
        	for (int i = 1; i <= 62; i++) cout << cnt_finish[i] << ' ';
			cout << '\n';
			cout << '\n';
	 	 	break;
	 	}
	 	if (num == k + 1) break;
	 	cerr << num << '\n';
	}
	
	for (int i = 1; i <= 62; i++)
		if (cnt_start[i] < cnt_finish[i]) cout << "-1\n", exit(0);

	for (int i = 1; i <= n; i++)
	{
	 	for (int j = 1; j <= m; j++) cout << start[i][j] << ' ';
	 	cout << '\n';
	}
	cout << '\n';

	for (int i = 1; i <= n; i++)
	{
	 	for (int j = 1; j <= m; j++) cout << finish[i][j] << ' ';
	 	cout << '\n';
	}
	cout << '\n';

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
		{
			int need = start[i][j];
			
			int posx = 0, posy = 0;
			bool fnd = false;
			for (int i1 = 1; i1 <= n && !fnd; i1++)
				for (int j1 = 1; j1 <= m && !fnd; j1++)
				{
				 	if (mp(i1, j1) < mp(i, j)) continue;
				 	if (finish[i1][j1] == need) {posx = i1; posy = j1; fnd = true;}
 				}
 			if (posx == 0)
 			{
 			 	for (int i1 = 1; i1 <= n && !fnd; i1++)
    				for (int j1 = 1; j1 <= m && !fnd; j1++)
    				{
    				 	if (mp(i1, j1) < mp(i, j)) continue;
    				 	if (finish[i1][j1] == 0) {posx = i1; posy = j1; fnd = true;}
     				}
 			}
 			move_to(posx, posy, i, j, ans);
		}
	
	reverse(ans.begin(), ans.end());
	cout << (int) ans.size() << '\n';
	for (const auto &[typ, x, y] : ans) cout << typ << ' ' << x << ' ' << y << '\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

3
4 5 3
ULDDRR
4 5 0
UUUUUUU
4 5 10
UUUUUUU

output:


result: