제출 #469087

#제출 시각아이디문제언어결과실행 시간메모리
469087gavgavFountain (eJOI20_fountain)C++17
0 / 100
1 ms204 KiB
#include <iostream> #include <vector> #include <stack> using namespace std; int main(){ freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); /* * Get dates about fountain. * Creating array in witch every number denotes index of the nearest number witch greater than this reservoir. * Indexes in this array means number of reservoir. */ int height, queries, streams_number = 0; scanf("%d%d", &height, &queries); int copy = height; int diameters[height], next_grater[height], capacities[height + 1]; capacities[height] = 0; vector <int> starts; stack <int> meowmeow; for (int i = 0; i < height; i++){ if (height != copy){ return 11; } scanf("%d%d", &diameters[i], &capacities[i]); if (!meowmeow.empty() && diameters[i] > diameters[meowmeow.top()]){ do{ next_grater[meowmeow.top()] = i; meowmeow.pop(); }while (!meowmeow.empty() && diameters[i] > diameters[meowmeow.top()]); } else{ streams_number++; starts.push_back(i); } meowmeow.push(i); } while (!meowmeow.empty()){ next_grater[meowmeow.top()] = height; meowmeow.pop(); } /* * Creating of any possible water path. */ int affiliation[height], indexes[height]; int lengths[streams_number] {}; vector <int> streams[streams_number]; for (int i = 0; i < streams_number; i++){ for (int j = starts[i], k = 0; j != height; j = next_grater[j], k++) { streams[i].push_back(j); lengths[i]++; indexes[j] = k; affiliation[j] = i; } streams[i].push_back(height); } /* * Creating postfix sums array. */ for (int i = height - 1; i > -1; i--){ capacities[i] += capacities[next_grater[i]]; } /* * Get queries and by binary search print answer. */ int volume, level, left, right, middle, answer; while (queries--){ scanf("%d%d", &level, &volume); level--; left = indexes[level] + 1, right = lengths[affiliation[level]], answer = streams[affiliation[level]][indexes[level]] + 1; while (left - right < 1){ middle = (left + right) / 2; if (volume > capacities[level] - capacities[streams[affiliation[level]][middle]]){ answer = streams[affiliation[level]][middle] + 1; left = middle + 1; } else { right = middle - 1; } } printf("%d\n", answer % (height + 1)); } }

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

fountain.cpp: In function 'int main()':
fountain.cpp:6:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:7:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d%d", &height, &queries);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf("%d%d", &diameters[i], &capacities[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fountain.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%d%d", &level, &volume);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...