제출 #942043

#제출 시각아이디문제언어결과실행 시간메모리
942043whatthemomooofun1729Jakarta Skyscrapers (APIO15_skyscraper)C++14
10 / 100
1 ms604 KiB
#include <iostream> #include <algorithm> #include <utility> #include <vector> #include <stack> #include <map> #include <queue> #include <set> #include <unordered_set> #include <unordered_map> #include <cstring> #include <cmath> #include <functional> #include <cassert> #include <iomanip> #include <numeric> #include <bitset> #include <sstream> #include <chrono> #include <random> #define ff first #define ss second #define ll long long #define ld long double #define PB push_back #define MP make_pair #define MT make_tuple #define EB emplace_back #define PoB pop_back #define LOG log2 #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define fch(t, v) for (auto t : v) #define sz(x) int(x.size()) #define rsz resize #define gp(x) vector<vector<x>> #define btree vector<pii> #define vll vector<ll> #define Max(a, b, c) max(max(a,b),c) #define fMax(a, b, c, d) max(Max(a, b, c), dp) #define Min(a, b, c) min(min(a,b),c) #define Mid(a, b, c) max(min(a, b), min(max(a, b), c)) #define st(a) set<a> #define gi greater<int> #define all(x) (x).begin(),(x).end() #define tri(x) tuple<x,x,x> #define pil pair<int, long> #define ull unsigned long long #define eps 1e-9 //#define debug(x) cout << '>' << #x << ':' << x << endl; using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} void println() {cerr << ">--------------------<" << endl;} void printm(vector<vector<int>>& mat) { cerr << "matrix: " << endl; for (int i = 0; i<(int)mat.size(); i++) {for (int j = 0; j<(int)mat[0].size(); j++) {cerr << mat[i][j] << " ";} cerr << endl;} } #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; // templates template <class T> bool ckmin(T &a, const T &b) {return b<a ? a = b, 1 : 0;} template <class T> bool ckmax(T &a, const T &b) {return b>a ? a = b, 1 : 0;} template <class T> using gr = greater<T>; mt19937_64 rng_ll(chrono::steady_clock::now().time_since_epoch().count()); template <class T> using vc = vector<T>; template <class T> using p_q = priority_queue<T>; template <class T> using pqg = priority_queue<T, vc<T>, gr<T>>; template <class T1, class T2> using pr = pair<T1, T2>; int rng(int M) {return (int)(rng_ll()%M);} constexpr int INF = (int)2e9; constexpr int MOD = 998244353; constexpr ll LL_INF = (ll)3e18; constexpr int mod = (int)1e9 + 7; constexpr ll inverse = 500000004LL; // inverse of 2 modulo 1e9 + 7 void setIO(const string& str) { ios_base::sync_with_stdio(false); cin.tie(nullptr); if (str.empty()) return; freopen((str + ".in").c_str(), "r", stdin); freopen((str + ".out").c_str(), "w", stdout); } int N, M; vc<vc<pii>> adj; vll dp; vi cnt; int start, dne; int main() { // TIME YOURSELF !!! setIO(""); cin >> N >> M; adj.rsz(N), dp.rsz(N, LL_INF), cnt.rsz(N, 0); for (int i = 0; i < M; ++i) { int b, p; cin >> b >> p; if (i == 0) start = b; else if (i == 1) dne = b; if (cnt[p] > p) continue; for (int j = b; j < N; j += p) { if (j != b) adj[b].PB({j, (j - b)/p}); } for (int j = b; j >= 0; j -= p) { if (j != b) adj[b].PB({j, (b - j)/p}); } cnt[p]++; } //assert(0 <= dne && dne < N); pqg<pr<ll, int>> pq; dp[start] = 0; pq.push({0, start}); while (!pq.empty()) { int v = pq.top().ss; ll d = pq.top().ff; pq.pop(); if (d != dp[v]) continue; if (v == dne) break; fch(to, adj[v]) { int u = to.ff, w = to.ss; if (ckmin(dp[u], dp[v] + w)) { pq.push({dp[u], u}); } } } cout << (dp[dne] == LL_INF ? -1 : dp[dne]); return 0; } // CHECK LONG LONGS, binary search on ans? // 5000 * 5000 size matrices are kinda big (potential mle) // Do something, start simpler // IBM motto: THINK

컴파일 시 표준 에러 (stderr) 메시지

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