QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#216197#5137. Towerjason#WA 17ms3608kbC++208.5kb2023-10-15 16:38:192023-10-15 16:38:20

Judging History

你现在查看的是最新测评结果

  • [2023-10-15 16:38:20]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:3608kb
  • [2023-10-15 16:38:19]
  • 提交

answer

#include<bits/stdc++.h>
#define pii pair<int,int>
#define x first
#define y second
#define int long long
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;

namespace Fread{
    const int SIZE=1<<16;
    char buf[SIZE],*S,*T;
    inline char getchar(){
        if(S==T){
            T=(S=buf)+fread(buf,1,SIZE,stdin);
            if(S==T)return '\n';
        }return *S++;
    }
}
using namespace Fread;
namespace Fwrite{
    const int SIZE=1<<16;
    char buf[SIZE],*S=buf,*T=buf+SIZE;
    inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}
    inline void putchar(char c){*S++ =c;if(S==T)flush();}
    struct NTR {~NTR(){flush();}} ztr;
}
using namespace Fwrite;
#define getchar Fread::getchar
#define putchar Fwrite::putchar
namespace Fastio{
    struct Reader{
        template <typename T> Reader& operator >> (T &x){
            x = 0;
            short f = 1;
            char c = getchar();
            while(c<'0'||c>'9')
	            {if(c=='-')f*=-1;c=getchar();}
            while(c>= '0'&&c<='9')
                x=(x<<3)+(x<<1)+(c^48),c=getchar();
            x *= f;
            return *this;
        }
        Reader& operator>>(double &x){
            x=0;
            double t=0;
            short f=1,s=0;
            char c=getchar();
            while((c<'0'||c>'9')&&c!='.')
	            {if(c=='-')f*=-1;c=getchar();}
            while(c>='0'&&c<='9'&&c!='.')
                x=x*10+(c^48),c=getchar();
            if(c=='.')c=getchar();
            else { x *= f; return *this; }
            while(c>='0'&&c<='9')
	            t=t*10+(c^48),s++,c=getchar();
            while (s--) t /= 10.0;
            x = (x + t) * f;
            return *this;
        }
        Reader& operator >> (long double &x){
            x = 0;
            long double t = 0;
            short f = 1, s = 0;
            char c = getchar();
            while((c<'0'||c>'9')&&c!='.')
	            {if(c=='-')f*=-1;c=getchar();}
            while (c >= '0' && c <= '9' && c != '.') 
                x = x * 10 + (c ^ 48), c = getchar();
            if (c == '.') c = getchar();
            else { x *= f; return *this; }
            while (c >= '0' && c <= '9') 
                t = t * 10 + (c ^ 48), s++, c = getchar();
            while (s--) t /= 10.0;
            x = (x + t) * f;
            return *this;
        }
        Reader& operator >> (__float128 &x){
            x = 0;
            __float128 t = 0;
            short f = 1, s = 0;
            char c = getchar();
            while((c<'0'||c>'9')&&c!='.')
	            {if (c == '-')f*=-1;c=getchar();}
            while (c >= '0' && c <= '9' && c != '.') 
                x = x * 10 + (c ^ 48), c = getchar();
            if (c == '.') c = getchar();
            else { x *= f; return *this; }
            while (c >= '0' && c <= '9') 
            t = t * 10 + (c ^ 48), s++, c = getchar();
            while (s--) t /= 10.0;
            x = (x + t) * f;
            return *this;
        }
        Reader& operator >> (char &c){
            c = getchar();
            while(c== ' '||c=='\n'||c=='\r')c=getchar();
            return *this;
        }
        Reader& operator >> (char *str){
            int len = 0;
            char c = getchar();
            while(c==' '||c=='\n'||c=='\r')c=getchar();
            while (c!=' '&&c!='\n'&&c!='\r')
                str[len++]=c,c=getchar();
            str[len] = '0';
            return *this;
        }
        Reader& operator >> (string &str){
            str.clear();
            char c = getchar();
            while(c==' '||c=='\n'||c=='\r')c=getchar();
            while(c!=' '&&c!='\n'&&c!='\r')
                str.push_back(c),c = getchar();
            return *this;
        }
        Reader() {}
    } cin;
    const char endl = '\n';
    struct Writer{
        const int Setprecision = 6;
        typedef int mxdouble;
        template <typename T> Writer& operator << (T x){
            if (x == 0) { putchar('0'); return *this; }
            if (x < 0) putchar('-'), x = -x;
            static short sta[40];
            short top = 0;
            while (x > 0) sta[++top] = x % 10, x /= 10;
            while (top>0)putchar(sta[top] + '0'),top--;
            return *this;
        }
        Writer& operator << (double x){
            if (x < 0) putchar('-'), x = -x;
            mxdouble _ = x;
            x -= (double)_;
            static short sta[40];
            short top = 0;
            while(_>0)sta[++top]=_%10,_/=10;
            if (top == 0) putchar('0');
            while(top>0)putchar(sta[top]+'0'),top--;
            putchar('.');
            for(int i=0;i<Setprecision;i++)x*=10;
            _ = x;
            while(_>0)sta[++top]=_%10,_/=10;
            for(int i=0;i<Setprecision-top;i++)putchar('0');
            while (top > 0) putchar(sta[top] + '0'), top--;
            return *this;
        }
        Writer& operator << (long double x){
            if (x < 0) putchar('-'), x = -x;
            mxdouble _ = x;
            x -= (long double)_;
            static short sta[40];
            short top = 0;
            while (_ > 0) sta[++top] = _ % 10, _ /= 10;
            if (top == 0) putchar('0');
            while (top > 0) putchar(sta[top] + '0'), top--;
            putchar('.');
            for (int i = 0; i < Setprecision; i++) x *= 10;
            _ = x;
            while (_ > 0) sta[++top] = _ % 10, _ /= 10;
            for(int i=0;i<Setprecision-top;i++)putchar('0');
            while (top > 0) putchar(sta[top] + '0'), top--;
            return *this;
        }
        Writer& operator << (__float128 x){
            if (x < 0) putchar('-'), x = -x;
            mxdouble _ = x;
            x -= (__float128)_;
            static short sta[40];
            short top = 0;
            while (_ > 0) sta[++top] = _ % 10, _ /= 10;
            if (top == 0) putchar('0');
            while (top > 0) putchar(sta[top] + '0'), top--;
            putchar('.');
            for (int i = 0; i < Setprecision; i++) x *= 10;
            _ = x;
            while (_ > 0) sta[++top] = _ % 10, _ /= 10;
            for(int i=0;i<Setprecision-top;i++)putchar('0');
            while (top > 0) putchar(sta[top] + '0'), top--;
            return *this;
        }
        Writer& operator <<(char c)
	        {putchar(c);return *this;}
        Writer& operator << (char *str){
            int cur = 0;
            while (str[cur]) putchar(str[cur++]);
            return *this;
        }
        Writer& operator << (const char *str){
            int cur = 0;
            while (str[cur]) putchar(str[cur++]);
            return *this;
        }
        Writer& operator << (string str){
            int st = 0, ed = str.size();
            while (st < ed) putchar(str[st++]);
            return *this;
        }
        Writer() {}
    } cout;
}
using namespace Fastio;
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl

const int N=2e5+5;
int a[N];
void slove(){
    int n,m;
    cin>>n>>m;
    unordered_set<int> st;
    vector<int> v[n+1];
    for(int i=1,tmp;i<=n;++i){
        cin>>a[i];
        tmp=a[i];
        while(tmp){
            st.insert(tmp);
            v[i].push_back(tmp);
            tmp/=2;
        }
        reverse(v[i].begin(),v[i].end());
    }
    int ans=1e9;
    for(auto &h:st){
//         cout<<"h : "<<h<<endl;
        int len=log2(h);
        for(int i=len;i>=-len;--i){
            if(h+i<=0)    break;
            int now=h+i;
//             cout<<"now : "<<now<<endl;
            vector<int> tmp;
            for(int i=1;i<=n;++i){
                int id=lower_bound(v[i].begin(),v[i].end(),now)-v[i].begin();
                int x,y;
                if(id==v[i].size()){
                    x=1e9;
                    y=now-v[i][id-1];
                }
                else{
                    x=v[i][id]-now + v[i].size()-id-1;
                    y=now-v[i][id]/2 + v[i].size()-id;
                }
//                 cout<<"x y : "<<x<<" "<<y<<endl;
                tmp.push_back(min(x,y));
            }
//             sort(tmp.begin(),tmp.end());
            nth_element(tmp.begin(),tmp.end(),tmp.begin()+n-m);
            int res=0;
            for(int i=0;i<n-m;++i){
                res += tmp[i];
            }
            ans = min(ans,res);
        }
    }
    cout<<ans<<"\n";
}

signed main()
{
    ios::sync_with_stdio(0);
    int t;cin>>t;
    while(t--){
        slove();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3548kb

input:

3
2 0
2 6
5 0
1 2 3 4 5
5 3
1 2 3 4 5

output:

2
4
1

result:

ok 3 number(s): "2 4 1"

Test #2:

score: -100
Wrong Answer
time: 17ms
memory: 3608kb

input:

10
272 118
11 14 49 94 71 62 46 45 74 22 15 36 7 37 27 35 96 85 75 78 76 64 23 59 17 35 71 28 96 82 5 66 2 48 57 31 88 10 61 73 79 23 19 52 39 76 48 98 5 39 48 51 90 90 60 27 47 24 24 56 48 27 39 21 38 18 20 9 62 83 47 15 51 22 73 74 7 80 64 60 86 74 59 7 84 38 99 31 42 60 52 41 63 88 59 90 77 40 68...

output:

575
43
543
155
786
655
1051
277
702
124

result:

wrong answer 1st numbers differ - expected: '454', found: '575'