Submission #414597

#TimeUsernameProblemLanguageResultExecution timeMemory
414597souvenir_vaynePatkice II (COCI21_patkice2)C++14
110 / 110
1487 ms97024 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <chrono> #define pb push_back #define INF 0x3f3f3f3f #define LINF 0x3f3f3f3f3f3f3f3f #define endl '\n' #define ll long long #define f first #define fin cin #define fout cout #define s second #define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0) #define debug(x) cout << "DEBUG " << x << endl #define debug2(x, y) cout << "DEBUG " << x << " " << y << endl #define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl #define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl #define all(x) x.begin(), x.end() #define left vadia #define lb lower_bound #define right puta using namespace std; using namespace __gnu_pbds; void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str( ),"w",stdout); } typedef pair<ll, ll> pii; typedef vector<vector<char>> mat; typedef pair<int, string> pis; const ll mod = 1e9+7, MAXN = 1e5; typedef vector<int> vi; typedef pair<int, pair<int, int>> piii; char m[2005][2005]; int dist[2005][2005]; pii pai[2005][2005]; priority_queue<piii, vector<piii>, greater<piii>> fila; pii start, e; int x[] = {1, -1, 0, 0}, l, c; int y[] = {0, 0, 1, -1}; int dijkstra() { for(int i = 0; i <= 2000; i++) for(int j = 0; j <= 2000; j++) dist[i][j] = INF; dist[start.f][start.s] = 0; fila.push({0, start}); while(!fila.empty()) { start = fila.top().s; int aux = fila.top().f; fila.pop(); //debug2(start.f, start.s); if(aux != dist[start.f][start.s]) continue; for(int i = 0; i < 4; i++) { int ni = start.f + x[i], nj = start.s + y[i]; if(ni < 0 or nj < 0 or ni >= l or nj >= c) continue; // debug2(ni, nj); if(!i && dist[ni][nj] > aux + (m[start.f][start.s] != 'v')) { dist[ni][nj] = aux + (m[start.f][start.s] != 'v'); fila.push({aux + (m[start.f][start.s] != 'v'), {ni, nj}}); pai[ni][nj] = {start.f, start.s}; } if(i == 1 && dist[ni][nj] > aux + (m[start.f][start.s] != '^')) { dist[ni][nj] = aux + (m[start.f][start.s] != '^'); fila.push({aux + (m[start.f][start.s] != '^'), {ni, nj}}); pai[ni][nj] = {start.f, start.s}; } if(i == 2 && dist[ni][nj] > aux + (m[start.f][start.s] != '>')) { dist[ni][nj] = aux + (m[start.f][start.s] != '>'); fila.push({aux + (m[start.f][start.s] != '>'), {ni, nj}}); pai[ni][nj] = {start.f, start.s}; } if(i == 3 && dist[ni][nj] > aux + (m[start.f][start.s] != '<')) { dist[ni][nj] = aux + (m[start.f][start.s] != '<'); fila.push({aux + (m[start.f][start.s] != '<'), {ni, nj}}); pai[ni][nj] = {start.f, start.s}; } } } return dist[e.f][e.s]; } int main(){ cin >> l >> c; for(int i = 0; i < l; i++) for(int j = 0; j < c; j++) { cin >> m[i][j]; if(m[i][j] == 'o') start = {i, j}; if(m[i][j] == 'x') e = {i, j}; } pii kek = start; cout << dijkstra()-1 << endl; while(pai[e.f][e.s] != kek) { for(int i = 0; i < 4; i++) { int ni = e.f + x[i], nj = e.s + y[i]; if(ni < 0 or nj < 0 or ni >= l or nj >= c or ni != pai[e.f][e.s].f or nj != pai[e.f][e.s].s) continue; if(!i) m[pai[e.f][e.s].f][pai[e.f][e.s].s] = '^'; if(!i) m[pai[e.f][e.s].f][pai[e.f][e.s].s] = '^'; if(i == 1) m[pai[e.f][e.s].f][pai[e.f][e.s].s] = 'v'; if(i == 2) m[pai[e.f][e.s].f][pai[e.f][e.s].s] = '<'; if(i == 3) m[pai[e.f][e.s].f][pai[e.f][e.s].s] = '>'; } e = pai[e.f][e.s]; } for(int i = 0; i < l; i++, cout << endl) for(int j = 0; j < c; j++) cout << m[i][j]; }

Compilation message (stderr)

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   freopen((s+".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |   freopen((s+".out").c_str( ),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...