답안 #1036123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1036123 2024-07-27T03:43:45 Z HNa_seawjing Robot (JOI21_ho_t4) C++14
100 / 100
313 ms 92724 KB
#include <bits/stdc++.h>
//code
#define fl(i,x,y,z) for(int i=x;i<=y;i=i+z)
#define fn(i,x,y,z) for(int i=x;i>=y;i=i-z)
#define rep(i,x,y) for(int i=x;i<y;i=i+1)
#define all(v) v.begin(),v.end()
#define pb push_back
#define tle cout<<"tle"<<endl
#define edl cout<<"\n"
#define el "\n"
#define getbit(x,i) ((x>>i)&1)
#define bitcnt __builtin_popcount
//ham
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define ld long double
#define inf 0x3f3f3f3f
#define m_p make_pair
#define int long long
using namespace std;
const ll mod=1e9+7;
vector< pii > a[600005];
vector<pair<int,pii>> g[600005];
int d[600005];
int t[600005];
bool vis[600005];
void dij(int x)
{
	fl(i,1,600005,1) d[i] = 1e18;
	priority_queue< pii , vector < pii > , greater < pii > > q;
	d[x] = 0;
	q.push(m_p(0, x));
	while (!q.empty())
	{
		auto p1 = q.top();
		int W = p1.fi;
		int x = p1.se;
		q.pop();
		if (vis[x])
			continue;
		vis[x] = 1;
		for (auto p2 : a[x])
		{
			int y = p2.fi;
			int w = p2.se;
			if (vis[y] || d[y] < W + w)
				continue;
			d[y] = W + w;
			q.push({W + w, y});
		}
	}
}
void sol()
{
	int n,m,x,y,c,p;
	cin >> n >> m;
	fl(i,1,m,1)
	{
		cin >> x >> y >> c >> p;
		g[x].push_back({c, {y, p}});
		g[y].push_back({c, {x, p}});
		a[x].push_back({y, p});
		a[y].push_back({x, p});
	}
	int cur = n;
	fl(i,1,n,1)
	{
		sort(g[i].begin(), g[i].end());
		for (auto x : g[i])
			t[x.fi] += x.se.se;
		for (auto x : g[i])
		{
			if (!vis[x.fi])
			{
				++cur;
				a[i].push_back(m_p(cur,0));
			}
			vis[x.fi] = 1;
			a[cur].push_back(m_p(x.se.fi, t[x.fi] - x.se.se));
			a[x.se.fi].push_back(m_p(cur, 0));
		}
		for (auto x : g[i])
		{
			t[x.fi] = 0;
			vis[x.fi] = 0;
		}
	}
	dij(1);
	if (d[n] == 1e18) cout << "-1";
	else cout << d[n];
}
signed main()
{
//    freopen("task.inp","r",stdin);
//    freopen("task.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    sol();
    return 0;
}
/*   /\_/\
    ( ._. )
    / >V< \
*/

Compilation message

Main.cpp: In function 'void dij(long long int)':
Main.cpp:31:24: warning: iteration 600004 invokes undefined behavior [-Waggressive-loop-optimizations]
   31 |  fl(i,1,600005,1) d[i] = 1e18;
      |                   ~~~~~^~~~~~
Main.cpp:3:34: note: within this loop
    3 | #define fl(i,x,y,z) for(int i=x;i<=y;i=i+z)
......
   31 |  fl(i,1,600005,1) d[i] = 1e18;
      |     ~~~~~~~~~~                    
Main.cpp:31:2: note: in expansion of macro 'fl'
   31 |  fl(i,1,600005,1) d[i] = 1e18;
      |  ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 33112 KB Output is correct
2 Correct 14 ms 33112 KB Output is correct
3 Correct 15 ms 33252 KB Output is correct
4 Correct 14 ms 33116 KB Output is correct
5 Correct 14 ms 33280 KB Output is correct
6 Correct 15 ms 33116 KB Output is correct
7 Correct 15 ms 33432 KB Output is correct
8 Correct 14 ms 33372 KB Output is correct
9 Correct 17 ms 33880 KB Output is correct
10 Correct 17 ms 33884 KB Output is correct
11 Correct 15 ms 33628 KB Output is correct
12 Correct 15 ms 33752 KB Output is correct
13 Correct 16 ms 33628 KB Output is correct
14 Correct 14 ms 33796 KB Output is correct
15 Correct 16 ms 33628 KB Output is correct
16 Correct 16 ms 33712 KB Output is correct
17 Correct 15 ms 33624 KB Output is correct
18 Correct 18 ms 33368 KB Output is correct
19 Correct 15 ms 33880 KB Output is correct
20 Correct 15 ms 33624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 104 ms 55012 KB Output is correct
2 Correct 56 ms 43208 KB Output is correct
3 Correct 139 ms 66156 KB Output is correct
4 Correct 71 ms 47056 KB Output is correct
5 Correct 313 ms 92724 KB Output is correct
6 Correct 283 ms 88204 KB Output is correct
7 Correct 212 ms 81144 KB Output is correct
8 Correct 246 ms 82256 KB Output is correct
9 Correct 259 ms 82104 KB Output is correct
10 Correct 142 ms 65224 KB Output is correct
11 Correct 90 ms 57500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 33112 KB Output is correct
2 Correct 14 ms 33112 KB Output is correct
3 Correct 15 ms 33252 KB Output is correct
4 Correct 14 ms 33116 KB Output is correct
5 Correct 14 ms 33280 KB Output is correct
6 Correct 15 ms 33116 KB Output is correct
7 Correct 15 ms 33432 KB Output is correct
8 Correct 14 ms 33372 KB Output is correct
9 Correct 17 ms 33880 KB Output is correct
10 Correct 17 ms 33884 KB Output is correct
11 Correct 15 ms 33628 KB Output is correct
12 Correct 15 ms 33752 KB Output is correct
13 Correct 16 ms 33628 KB Output is correct
14 Correct 14 ms 33796 KB Output is correct
15 Correct 16 ms 33628 KB Output is correct
16 Correct 16 ms 33712 KB Output is correct
17 Correct 15 ms 33624 KB Output is correct
18 Correct 18 ms 33368 KB Output is correct
19 Correct 15 ms 33880 KB Output is correct
20 Correct 15 ms 33624 KB Output is correct
21 Correct 104 ms 55012 KB Output is correct
22 Correct 56 ms 43208 KB Output is correct
23 Correct 139 ms 66156 KB Output is correct
24 Correct 71 ms 47056 KB Output is correct
25 Correct 313 ms 92724 KB Output is correct
26 Correct 283 ms 88204 KB Output is correct
27 Correct 212 ms 81144 KB Output is correct
28 Correct 246 ms 82256 KB Output is correct
29 Correct 259 ms 82104 KB Output is correct
30 Correct 142 ms 65224 KB Output is correct
31 Correct 90 ms 57500 KB Output is correct
32 Correct 88 ms 66768 KB Output is correct
33 Correct 92 ms 62664 KB Output is correct
34 Correct 159 ms 71364 KB Output is correct
35 Correct 132 ms 63840 KB Output is correct
36 Correct 195 ms 69024 KB Output is correct
37 Correct 193 ms 79836 KB Output is correct
38 Correct 208 ms 85172 KB Output is correct
39 Correct 136 ms 79568 KB Output is correct
40 Correct 260 ms 85332 KB Output is correct
41 Correct 278 ms 85328 KB Output is correct
42 Correct 252 ms 80324 KB Output is correct
43 Correct 98 ms 58580 KB Output is correct
44 Correct 168 ms 83532 KB Output is correct
45 Correct 220 ms 72780 KB Output is correct
46 Correct 213 ms 69176 KB Output is correct
47 Correct 210 ms 73748 KB Output is correct
48 Correct 289 ms 92480 KB Output is correct