답안 #111112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
111112 2019-05-13T16:54:45 Z CodeKracker Detecting Molecules (IOI16_molecules) C++14
컴파일 오류
0 ms 0 KB
/*input

*/
/**
    Author: Kristopher Paul
    Date Created: 13-05-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#define ll long long
//#define int ll
#define pb push_back
#define INF 0x3f3f3f3f //0x3f3f3f3f = 63
#define MOD 1000000007
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

vector<int> find_subset(int l,int u,vector<int> w){
    int al,ar,len;
    al = ar = -1;
    len = -1;
    vector<pii> vec;
    FOR(i,0,w.size()){
        vec.pb({w[i],i});
    }
    sort(vec.begin(),vec.end());
    int i = 0,j = 0;
    bool vis[w.size()] = {};
    ll csum = 0;
    vector<int> ans;
    if(vec[0].first > u){
        return ans;
    }
    while(j < w.size()){
        if(!vis[j]){
            vis[j] = true;
            csum += vec[j].first;
        }
        if(csum >= l && csum <= u){
            if((j-i+1) > len){
                len = (j-i+1);
                al = i;
                ar = j;
            }
            j++;
        }else if(csum < l){
            j++;
        }else{
            csum -= vec[i].first;
            i++;
        }
    }
    if(len == -1){
        return ans;
    }
    FOR(i,al,ar+1){
        ans.pb(vec[i].second);
    }
    return ans;
}

void solve(){
    vector<int> tst;
    int l,u;
    cin >> l >> u;
    int n;
    cin >> n;
    FOR(i,0,n){
        int x;
        cin >> x;
        tst.pb(x);
    }
    vector<int> ans = find_subset(l,u,tst);
    FOR(i,0,ans.size()){
        cout << ans[i] << " ";
    }
    cout << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}

Compilation message

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:23:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i,a,b) for (int i = a; i < b; i++)
molecules.cpp:63:9:
     FOR(i,0,w.size()){
         ~~~~~~~~~~~~                  
molecules.cpp:63:5: note: in expansion of macro 'FOR'
     FOR(i,0,w.size()){
     ^~~
molecules.cpp:74:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(j < w.size()){
           ~~^~~~~~~~~~
molecules.cpp: In function 'void solve()':
molecules.cpp:23:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define FOR(i,a,b) for (int i = a; i < b; i++)
molecules.cpp:114:9:
     FOR(i,0,ans.size()){
         ~~~~~~~~~~~~~~                
molecules.cpp:114:5: note: in expansion of macro 'FOR'
     FOR(i,0,ans.size()){
     ^~~
/tmp/ccsCAhub.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccmsriAY.o:molecules.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status