結果

問題 No.332 数列をプレゼントに
ユーザー LayCurseLayCurse
提出日時 2015-12-25 00:25:51
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 3,662 bytes
コンパイル時間 1,497 ms
コンパイル使用メモリ 162,840 KB
実行使用メモリ 38,976 KB
最終ジャッジ日時 2023-10-19 03:04:17
合計ジャッジ時間 5,505 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,352 KB
testcase_01 AC 4 ms
8,356 KB
testcase_02 AC 3 ms
6,304 KB
testcase_03 AC 3 ms
6,340 KB
testcase_04 AC 8 ms
10,432 KB
testcase_05 AC 35 ms
30,912 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void reader(double*)’:
main.cpp:15:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 | void reader(double *x){scanf("%lf",x);}
      |                        ~~~~~^~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[17000000]; void *mem = memarr;
#define MD 1000000007

int getPrime(int N, int res[]){int i,a,b,s=1,f[4780],S=1;const int r=23000;bool B[r],*p=B;N/=2;res[0]=2;b=min(r,N);REP(i,1,b)p[i]=1;REP(i,1,b)if(p[i]){res[s++]=2*i+1;f[S]=2*i*(i+1);if(f[S]<N){for(;f[S]<r;f[S]+=res[S])p[f[S]]=0;S++;}}for(a=r;a<N;a+=r){b=min(a+r,N);p-=r;REP(i,a,b)p[i]=1;REP(i,1,S)for(;f[i]<b;f[i]+=res[i])p[f[i]]=0;REP(i,a,b)if(p[i])res[s++]=2*i+1;}return s;}

int N, A[120];
ll X;
int ps, p[100000], md;

int dp[120][100000];
int res[120];

int solve(int i, int j){
  int k;
  ll chk;

  if(i==-1 && j==0){
    chk = 0;
    rep(k,N) if(res[k]) chk += A[k];
    if(chk==X) return 1;
    return 0;
  }
  if(i==-1) return 0;

  if(solve(i-1, j)) return 1;

  if(j==A[i]%md || dp[i][((j-A[i])%md+md)%md]){
    res[i] = 1;
    if(solve(i-1, ((j-A[i])%md+md)%md)) return 1;
    res[i] = 0;
  }

  return 0;
}

int main(){
  int i, j, k, tar, loop;
  ll chk;

  reader(&N,&X);
  rep(i,N) reader(A+i);

  ps = getPrime(100000, p);
  srand(time(NULL));

  rep(loop,20){
    md = p[(ps/2)+rand()%(ps/2)];

    tar = X % md;
    rep(i,N+1) rep(j,md) dp[i][j] = 0;
    rep(i,N){
      dp[i+1][A[i]%md] = 1;
      rep(j,md) dp[i+1][(j+A[i])%md] |= dp[i][j];
      rep(j,md) dp[i+1][j] |= dp[i][j];
    }

//    writerLn(tar);
//    rep(i,N+1) rep(j,md) if(dp[i][j]) printf("%d %d %d\n",i,j,dp[i][j]);
//    puts("");

    if(dp[N][tar]){
      rep(i,N) res[i] = 0;
      k = solve(N-1, tar);
      if(k){
        rep(i,N) mypc(res[i]?'o':'x');
        mypc('\n');
        return 0;
      }
    }

    break;
  }

  writerLn("No");

  return 0;
}
0