Submission #20649

#TimeUsernameProblemLanguageResultExecution timeMemory
20649model_code장애물 경기 (KOI16_dd)C++14
100 / 100
86 ms4740 KiB
#include<stdio.h> #include<algorithm> #include<vector> #include<set> using namespace std; struct lin { int x, y1, y2; bool operator< (const lin& c) const { return x < c.x; } }ba[101010]; struct st { int y, val; bool operator< (const st& c) const { return y < c.y; } }sim; set<st> sets; set<st>::iterator it; int n, sy, tx; int main() { int i; scanf("%d%d%d", &n, &sy, &tx); for (i = 0; i < n; i++)scanf("%d%d%d", &ba[i].x, &ba[i].y1, &ba[i].y2); sort(ba, ba + n); sim = { sy,0 }; sets.insert(sim); for (i = 0; i < n; i++) { st im; int lmin = (int)1e9, rmin = (int)1e9; sim = { ba[i].y1,0 }; it = sets.lower_bound(sim); if (it == sets.end())continue; vector<int> v; for (; it != sets.end(); it++) { im = *it; if (im.y > ba[i].y2)break; v.push_back(im.y); if(im.y < ba[i].y2) lmin = min(lmin, im.val + im.y - ba[i].y1); if(im.y > ba[i].y1) rmin = min(rmin, im.val + ba[i].y2 - im.y); } for (unsigned int j = 0; j < v.size(); j++) sim = { v[j],0 }, sets.erase(sim); if(lmin < (int)1e9) sim = { ba[i].y1,lmin }, sets.insert(sim); if(rmin < (int)1e9) sim = { ba[i].y2,rmin }, sets.insert(sim); } int ans = (int)1e9; for (it = sets.begin(); it != sets.end(); it++) { if (ans > (*it).val)ans = (*it).val; } printf("%d\n", ans + tx); vector<int> v; for (it = sets.begin(); it != sets.end(); it++) { if (ans == (*it).val)v.push_back((*it).y); } printf("%d ", v.size()); for(i = 0; i < v.size(); i++) printf("%d ", v[i]); puts(""); return 0; }

Compilation message (stderr)

dd.cpp: In function 'int main()':
dd.cpp:68:23: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
 printf("%d ", v.size());
                       ^
dd.cpp:69:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 for(i = 0; i < v.size(); i++) printf("%d ", v[i]);
              ^
dd.cpp:29:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf("%d%d%d", &n, &sy, &tx);
                              ^
dd.cpp:30:71: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 for (i = 0; i < n; i++)scanf("%d%d%d", &ba[i].x, &ba[i].y1, &ba[i].y2);
                                                                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...