제출 #1147640

#제출 시각아이디문제언어결과실행 시간메모리
1147640cntourDetecting Molecules (IOI16_molecules)C++20
100 / 100
56 ms5192 KiB
#include <bits/stdc++.h> using namespace std; vector<int> find_subset(int l, int u, vector<int> w) { int n = w.size(); // Create pairs of {weight, index} vector<pair<long long, int>> molecules(n); for(int i = 0; i < n; i++) { molecules[i] = {w[i], i}; } // Sort by weight sort(molecules.begin(), molecules.end()); // Use two pointers to find a valid range int left = 0; long long sum = 0; for(int right = 0; right < n; right++) { sum += molecules[right].first; // If sum becomes too large, remove elements from left while(left <= right && sum > u) { sum -= molecules[left].first; left++; } // Check if current window has valid sum if(sum >= l && sum <= u) { vector<int> result; // Collect indices from the valid window for(int i = left; i <= right; i++) { result.push_back(molecules[i].second); } // Sort indices as required sort(result.begin(), result.end()); return result; } } // No solution found return vector<int>(); }

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

molecules.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
molecules_c.h:1:9: warning: #pragma once in main file
    1 | #pragma once
      |         ^~~~
#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...