제출 #910639

#제출 시각아이디문제언어결과실행 시간메모리
910639josanneo22Teleporters (IOI08_teleporters)C++17
100 / 100
295 ms35412 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; #define L(i,j,k) for(int i=(j);i<=(k);++i) #define R(i,j,k) for(int i=(j);i>=(k);--i) namespace fast { #pragma GCC optimize(Ofast) #pragma GCC optimization (unroll-loops) #pragma GCC target(avx,avx2,fma) #pragma GCC target(sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native) #pragma GCC optimize(3) #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC optimize("-fpeephole2") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-fsched-spec") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-falign-jumps") #pragma GCC optimize("-falign-loops") #pragma GCC optimize("-falign-labels") #pragma GCC optimize("-fdevirtualize") #pragma GCC optimize("-fcaller-saves") #pragma GCC optimize("-fcrossjumping") #pragma GCC optimize("-fthread-jumps") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-fwhole-program") #pragma GCC optimize("-freorder-blocks") #pragma GCC optimize("-fschedule-insns") #pragma GCC optimize("inline-functions") #pragma GCC optimize("-ftree-tail-merge") #pragma GCC optimize("-fschedule-insns2") #pragma GCC optimize("-fstrict-aliasing") #pragma GCC optimize("-fstrict-overflow") #pragma GCC optimize("-falign-functions") #pragma GCC optimize("-fcse-skip-blocks") #pragma GCC optimize("-fcse-follow-jumps") #pragma GCC optimize("-fsched-interblock") #pragma GCC optimize("-fpartial-inlining") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("-freorder-functions") #pragma GCC optimize("-findirect-inlining") #pragma GCC optimize("-fhoist-adjacent-loads") #pragma GCC optimize("-frerun-cse-after-loop") #pragma GCC optimize("inline-small-functions") #pragma GCC optimize("-finline-small-functions") #pragma GCC optimize("-ftree-switch-conversion") #pragma GCC optimize("-foptimize-sibling-calls") #pragma GCC optimize("-fexpensive-optimizations") #pragma GCC optimize("-funsafe-loop-optimizations") #pragma GCC optimize("inline-functions-called-once") #pragma GCC optimize("-fdelete-null-pointer-checks") } using namespace fast; inline string read_string() { char ch = getchar(); string st1 = ""; while (!((ch >= 'A') && (ch <= 'Z'))) ch = getchar(); while ((ch >= 'A') && (ch <= 'Z')) st1 += ch, ch = getchar(); return st1; } char buf[1 << 23], * p1 = buf, * p2 = buf; #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) template<typename T> inline void re(T & x) { x = 0; T f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch - 48); ch = getchar(); } x *= f; } template<typename x, typename... y>void re(x & a, y&... b) { re(a); re(b...); } template<typename T> inline void ps(T x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) ps(x / 10); putchar(x % 10 + '0'); } template<typename x, typename... y>void ps(x & a, y&... b) { ps(a); putchar(' '); ps(b...); } #define sp putchar(' ') #define nl putchar('\n') struct node { int index, pos; }a[2000005]; inline bool cmp(const node& A, const node& B) { return A.pos < B.pos; } int nxt[2000005], N, M, sz[2000005], cnt; bool vis[2000005]; void dfs(int u) { if (vis[u]) return; vis[u] = true; sz[cnt]++; if (!vis[nxt[u]]) dfs(nxt[u]); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); re(N, M); L(i, 1, N) { int l, r; re(l, r); a[i].index = i; a[i].pos = l; a[i + N].index = i + N; a[i + N].pos = r; } sort(a + 1, a + 2 * N + 1, cmp); L(i, 1, N * 2) { if (a[i].index >= N + 1) { int x = a[i].index - N, y = a[i].index; a[i].index = y; a[i].pos = x; } else { int x = a[i].index, y = N + a[i].index; a[i].index = x; a[i].pos = y; } } a[0].pos = 0; L(i, 1, 2 * N) nxt[a[i - 1].pos] = a[i].index; nxt[a[2 * N].pos] = 0; L(i, 0, 2 * N) { if (!vis[i]) { cnt++; sz[cnt] = 0; dfs(i); } } sort(sz + 2, sz + cnt + 1, greater<int>()); int ans = sz[1] - 1; L(i, 2, cnt) { if (M == 0) break; M--; ans += sz[i]; ans += 2; } if (M & 1) { ans++; M--; } ans += 2 * M; ps(ans); }

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

teleporters.cpp:10: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   10 | #pragma GCC optimization (unroll-loops)
      | 
teleporters.cpp:9:22: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
    9 | #pragma GCC optimize(Ofast)
      |                      ^~~~~
teleporters.cpp:11:20: warning: '#pragma GCC option' is not a string [-Wpragmas]
   11 | #pragma GCC target(avx,avx2,fma)
      |                    ^~~
teleporters.cpp:12:20: warning: '#pragma GCC option' is not a string [-Wpragmas]
   12 | #pragma GCC target(sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native)
      |                    ^~~
teleporters.cpp:32:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
   32 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
teleporters.cpp:39:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
   39 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
teleporters.cpp:41:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
   41 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
teleporters.cpp:55:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
   55 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
teleporters.cpp:61:27: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   61 | inline string read_string() {
      |                           ^
teleporters.cpp:61:27: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
teleporters.cpp:61:27: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
teleporters.cpp:61:27: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
teleporters.cpp:69:42: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   69 | template<typename T> inline void re(T & x) { x = 0; T f = 1; char ch = getchar();  while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch - 48); ch = getchar(); } x *= f; }
      |                                          ^
teleporters.cpp:69:42: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
teleporters.cpp:69:42: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
teleporters.cpp:69:42: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
teleporters.cpp:70:58: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   70 | template<typename x, typename... y>void re(x & a, y&... b) { re(a); re(b...); }
      |                                                          ^
teleporters.cpp:70:58: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
teleporters.cpp:70:58: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
teleporters.cpp:70:58: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
teleporters.cpp:71:40: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   71 | template<typename T> inline void ps(T x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9)  ps(x / 10); putchar(x % 10 + '0'); }
      |                                        ^
teleporters.cpp:71:40: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
teleporters.cpp:71:40: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
teleporters.cpp:71:40: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
teleporters.cpp:72:58: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   72 | template<typename x, typename... y>void ps(x & a, y&... b) { ps(a); putchar(' '); ps(b...); }
      |                                                          ^
teleporters.cpp:72:58: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
teleporters.cpp:72:58: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
teleporters.cpp:72:58: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
teleporters.cpp:79:45: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   79 | inline bool cmp(const node& A, const node& B) { return A.pos < B.pos; }
      |                                             ^
teleporters.cpp:79:45: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
teleporters.cpp:79:45: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
teleporters.cpp:79:45: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
teleporters.cpp:82:15: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   82 | void dfs(int u) {
      |               ^
teleporters.cpp:82:15: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
teleporters.cpp:82:15: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
teleporters.cpp:82:15: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
teleporters.cpp:88:10: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   88 | int main() {
      |          ^
teleporters.cpp:88:10: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
teleporters.cpp:88:10: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
teleporters.cpp:88:10: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
#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...
#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...
#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...
#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...