QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#759224#5137. Towerfrankly6Compile Error//C++171.4kb2024-11-17 23:20:292024-11-17 23:20:29

Judging History

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

  • [2024-11-17 23:20:29]
  • 评测
  • [2024-11-17 23:20:29]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
using namespace std;
const int MX=505;
const int inf=0x3fffffff;

int T, N, M;
int ar[MX];
map<int,int> mp;
int read()
{
    int r=0, f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
    return r*f;
}
int main()
{
    // freopen("testdata.in","r",stdin);
    T=read();
    while(T--)
    {
        mp.clear();
        N=read(); M=read();
        for(int i=1;i<=N;i++) 
        {
            ar[i]=read();
            int tmp=ar[i];
            while(tmp) mp[tmp]=1, tmp/=2;
        }
        int ans=inf;
        for(auto [tar,tag]:mp)
        {
            int br[MX]={}, cr[MX]={}, ta=0;
            memcpy(cr,ar,sizeof(ar));
            for(int i=1;i<=N;i++)
            {
                if(cr[i]<tar) br[i]=tar-cr[i];
                else
                {
                    while(cr[i]/2>=tar) cr[i]/=2, br[i]++;
                    br[i]+=cr[i]-tar;
                }
                // cout << "   br[i]=" << br[i] << '\n';
            }
            sort(br+1,br+1+N);
            for(int i=1;i<=N-M;i++)
                ta+=br[i];
            // cout << "tar=" << tar << ", ta=" << ta << '\n';
            ans=min(ans,ta);    
        }
        cout << ans << '\n';
    }
    return (0-0);
}

Details

answer.code: In function ‘int main()’:
answer.code:37:13: error: ‘memcpy’ was not declared in this scope
   37 |             memcpy(cr,ar,sizeof(ar));
      |             ^~~~~~
answer.code:5:1: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
    4 | #include<map>
  +++ |+#include <cstring>
    5 | using namespace std;