Submission #1075147

# Submission time Handle Problem Language Result Execution time Memory
1075147 2024-08-25T19:06:38 Z pawned Text editor (CEOI24_editor) C++17
0 / 100
120 ms 20060 KB
#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;

const char nl = '\n';

void fastIO() {
	ios::sync_with_stdio(false);
	cin.tie(0);
}

int dirX[4] = {-1, 1, 0, 0};
int dirY[4] = {0, 0, -1, 1};

const int MAX = 5005;

int main() {
	fastIO();
	int N;
	cin>>N;
	int x1, y1, x2, y2;
	cin>>x1>>y1>>x2>>y2;
	x1--; y1--; x2--; y2--;
	vi L(N, 0);
	for (int i = 0; i < N; i++) {
		cin>>L[i];
		L[i]++;
	}
	vector<vi> dist(N, vi(MAX, 1e9));
	queue<ii> q;	// {x, y}
	q.push({x1, y1});
	dist[x1][y1] = 0;
	while (!q.empty()) {
		ii p = q.front();
//		cout<<"at "<<p.fi<<", "<<p.se<<endl;
		q.pop();
		for (int i = 0; i < 4; i++) {
			int nx = p.fi + dirX[i];
			int ny = p.se + dirY[i];
			if (nx < 0 || nx >= N)	// can't go up / down when at edge
				continue;
			if (nx == 0 && ny == -1)	// can't go left at start
				continue;
			if (nx == N - 1 && ny == L[N - 1])	// can't go right at end
				continue;
			if (ny == L[nx]) {
				nx++;
				ny = 0;
			}
			else if (ny == -1) {
				nx--;
				ny = L[nx] - 1;
			}
			ny = min(ny, L[nx] - 1);
			if (0 <= nx && nx < N && ny >= 0 && ny < L[nx] && dist[nx][ny] == 1e9) {
//				cout<<"going to "<<nx<<" "<<ny<<endl;
				dist[nx][ny] = dist[p.fi][p.se] + 1;
				q.push({nx, ny});
			}
		}
	}
//	cout<<"ANSWER: ";
	cout<<dist[x2][y2]<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 32 ms 19036 KB Output is correct
5 Correct 30 ms 16220 KB Output is correct
6 Correct 12 ms 17756 KB Output is correct
7 Correct 32 ms 18860 KB Output is correct
8 Correct 120 ms 20060 KB Output is correct
9 Incorrect 73 ms 16216 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Runtime error 1 ms 604 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1 ms 604 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Runtime error 1 ms 604 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -