답안 #919912

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919912 2024-02-01T20:33:16 Z HMCarinVII Type Printer (IOI08_printer) C++17
0 / 100
414 ms 2996 KB
#include <iostream>
#include <bits/stdc++.h>
#define pp push_back
#define ll long long
#define pi 3.14159265358979323846
#define lp(n); for(int i=0;i<n;i++)
#define lli long long int
#define lpj(n); for(int j=0;j<n;j++)
#define lpk(n); for(int k=0;k<n;k++)
using namespace std;

const int N= (int)1e6 + 1; const long long mod=1e9+7; const double eps=1e-10;

long long int power(lli base,lli powr)
{
    if(!powr){return 1;}
    lli sq=power(base,powr>>1);
    return sq*sq*((powr&1)? base:1);
}

/*ll fact[N]={1},invfac[N]={1};
void factorial()
{
    fact[0]=fact[1]=invfac[0]=invfac[1]=1;
    for(int i=2; i<N; i++)
    {
        fact[i]=(fact[i-1]*i)%mod;
        invfac[i]=power(fact[i],mod-2);
    }
    return;
}


int modinv(int a, int x)
{
    for (int i = 1; i < x; i++)
        if (((a % x) * (i% x)) % x == 1)
            return i;
}*/
//ll dist(ll x,ll y,ll a,ll b){x-=a; x=power(x,2); y-=b; y=power(y,2); return sqrt(x+y);}
string s;
void printer(string x)
{
     lp(x.size())
     {
         if(x[i]!='-'){s+=x[i];}
     }
     s+='P';
}
void dash(int d)
{
    lp(d){s+='-';}
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    cout<<setprecision(10);cout<<fixed;
    // freopen("triangles.in", "r", stdin); freopen("triangles.out", "w", stdout);
     int n,ans=0;
     cin>>n;
     vector<string> v;
     lp(n){string x; cin>>x ; v.pp(x);}
     sort(v.begin(),v.end());
     for(int i=0;i<n;i++)
     {
         int d=v[i].size();
          printer(v[i]);
          if(i<n-1)
          {
              lpj(min(v[i].size(),v[i+1].size()))
              {
                  if(v[i][j]==v[i+1][j]){v[i+1][j]='-'; d--;}
                  else{break;}
              }
              dash(d);
          }
     }
     cout<<s.size()-n<<endl;
     lp(s.size()){cout<<s[i]<<endl;}

   return 0;

}

Compilation message

printer.cpp: In function 'void printer(std::string)':
printer.cpp:6:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define lp(n); for(int i=0;i<n;i++)
      |                            ~^~~~~~~
    7 | #define lli long long int
      | ~~~~~~~~~~~~~~~~~~~~~~~~~    
    8 | #define lpj(n); for(int j=0;j<n;j++)
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    9 | #define lpk(n); for(int k=0;k<n;k++)
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   10 | using namespace std;
      | ~~~~~~~~~~~~~~~~~~~~         
   11 | 
      |                              
   12 | const int N= (int)1e6 + 1; const long long mod=1e9+7; const double eps=1e-10;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   13 | 
      |                              
   14 | long long int power(lli base,lli powr)
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   15 | {
      | ~                            
   16 |     if(!powr){return 1;}
      |     ~~~~~~~~~~~~~~~~~~~~     
   17 |     lli sq=power(base,powr>>1);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 |     return sq*sq*((powr&1)? base:1);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   19 | }
      | ~                            
   20 | 
      |                              
   21 | /*ll fact[N]={1},invfac[N]={1};
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   22 | void factorial()
      | ~~~~~~~~~~~~~~~~             
   23 | {
      | ~                            
   24 |     fact[0]=fact[1]=invfac[0]=invfac[1]=1;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   25 |     for(int i=2; i<N; i++)
      |     ~~~~~~~~~~~~~~~~~~~~~~   
   26 |     {
      |     ~                        
   27 |         fact[i]=(fact[i-1]*i)%mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~
   28 |         invfac[i]=power(fact[i],mod-2);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   29 |     }
      |     ~                        
   30 |     return;
      |     ~~~~~~~                  
   31 | }
      | ~                            
   32 | 
      |                              
   33 | 
      |                              
   34 | int modinv(int a, int x)
      | ~~~~~~~~~~~~~~~~~~~~~~~~     
   35 | {
      | ~                            
   36 |     for (int i = 1; i < x; i++)
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |         if (((a % x) * (i% x)) % x == 1)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   38 |             return i;
      |             ~~~~~~~~~        
   39 | }*/
      | ~~~                          
   40 | //ll dist(ll x,ll y,ll a,ll b){x-=a; x=power(x,2); y-=b; y=power(y,2); return sqrt(x+y);}
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   41 | string s;
      | ~~~~~~~~~                    
   42 | void printer(string x)
      | ~~~~~~~~~~~~~~~~~~~~~~       
   43 | {
      | ~                            
   44 |      lp(x.size())
      |      ~~~~~~~~~~~             
printer.cpp:44:6: note: in expansion of macro 'lp'
   44 |      lp(x.size())
      |      ^~
printer.cpp: In function 'int main()':
printer.cpp:8:30: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
    8 | #define lpj(n); for(int j=0;j<n;j++)
      |                             ~^~~~~~~
    9 | #define lpk(n); for(int k=0;k<n;k++)
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   10 | using namespace std;
      | ~~~~~~~~~~~~~~~~~~~~          
   11 | 
      |                               
   12 | const int N= (int)1e6 + 1; const long long mod=1e9+7; const double eps=1e-10;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   13 | 
      |                               
   14 | long long int power(lli base,lli powr)
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   15 | {
      | ~                             
   16 |     if(!powr){return 1;}
      |     ~~~~~~~~~~~~~~~~~~~~      
   17 |     lli sq=power(base,powr>>1);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 |     return sq*sq*((powr&1)? base:1);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   19 | }
      | ~                             
   20 | 
      |                               
   21 | /*ll fact[N]={1},invfac[N]={1};
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   22 | void factorial()
      | ~~~~~~~~~~~~~~~~              
   23 | {
      | ~                             
   24 |     fact[0]=fact[1]=invfac[0]=invfac[1]=1;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   25 |     for(int i=2; i<N; i++)
      |     ~~~~~~~~~~~~~~~~~~~~~~    
   26 |     {
      |     ~                         
   27 |         fact[i]=(fact[i-1]*i)%mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~
   28 |         invfac[i]=power(fact[i],mod-2);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   29 |     }
      |     ~                         
   30 |     return;
      |     ~~~~~~~                   
   31 | }
      | ~                             
   32 | 
      |                               
   33 | 
      |                               
   34 | int modinv(int a, int x)
      | ~~~~~~~~~~~~~~~~~~~~~~~~      
   35 | {
      | ~                             
   36 |     for (int i = 1; i < x; i++)
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |         if (((a % x) * (i% x)) % x == 1)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   38 |             return i;
      |             ~~~~~~~~~         
   39 | }*/
      | ~~~                           
   40 | //ll dist(ll x,ll y,ll a,ll b){x-=a; x=power(x,2); y-=b; y=power(y,2); return sqrt(x+y);}
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   41 | string s;
      | ~~~~~~~~~                     
   42 | void printer(string x)
      | ~~~~~~~~~~~~~~~~~~~~~~        
   43 | {
      | ~                             
   44 |      lp(x.size())
      |      ~~~~~~~~~~~~             
   45 |      {
      |      ~                        
   46 |          if(x[i]!='-'){s+=x[i];}
      |          ~~~~~~~~~~~~~~~~~~~~~~~
   47 |      }
      |      ~                        
   48 |      s+='P';
      |      ~~~~~~~                  
   49 | }
      | ~                             
   50 | void dash(int d)
      | ~~~~~~~~~~~~~~~~              
   51 | {
      | ~                             
   52 |     lp(d){s+='-';}
      |     ~~~~~~~~~~~~~~            
   53 | }
      | ~                             
   54 | int main()
      | ~~~~~~~~~~                    
   55 | {
      | ~                             
   56 |     ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   57 |     cout<<setprecision(10);cout<<fixed;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   58 |     // freopen("triangles.in", "r", stdin); freopen("triangles.out", "w", stdout);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   59 |      int n,ans=0;
      |      ~~~~~~~~~~~~             
   60 |      cin>>n;
      |      ~~~~~~~                  
   61 |      vector<string> v;
      |      ~~~~~~~~~~~~~~~~~        
   62 |      lp(n){string x; cin>>x ; v.pp(x);}
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   63 |      sort(v.begin(),v.end());
      |      ~~~~~~~~~~~~~~~~~~~~~~~~ 
   64 |      for(int i=0;i<n;i++)
      |      ~~~~~~~~~~~~~~~~~~~~     
   65 |      {
      |      ~                        
   66 |          int d=v[i].size();
      |          ~~~~~~~~~~~~~~~~~~   
   67 |           printer(v[i]);
      |           ~~~~~~~~~~~~~~      
   68 |           if(i<n-1)
      |           ~~~~~~~~~           
   69 |           {
      |           ~                   
   70 |               lpj(min(v[i].size(),v[i+1].size()))
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:70:15: note: in expansion of macro 'lpj'
   70 |               lpj(min(v[i].size(),v[i+1].size()))
      |               ^~~
printer.cpp:6:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    6 | #define lp(n); for(int i=0;i<n;i++)
      |                            ~^~~~~~~
    7 | #define lli long long int
      | ~~~~~~~~~~~~~~~~~~~~~~~~~    
    8 | #define lpj(n); for(int j=0;j<n;j++)
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    9 | #define lpk(n); for(int k=0;k<n;k++)
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   10 | using namespace std;
      | ~~~~~~~~~~~~~~~~~~~~         
   11 | 
      |                              
   12 | const int N= (int)1e6 + 1; const long long mod=1e9+7; const double eps=1e-10;
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   13 | 
      |                              
   14 | long long int power(lli base,lli powr)
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   15 | {
      | ~                            
   16 |     if(!powr){return 1;}
      |     ~~~~~~~~~~~~~~~~~~~~     
   17 |     lli sq=power(base,powr>>1);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   18 |     return sq*sq*((powr&1)? base:1);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   19 | }
      | ~                            
   20 | 
      |                              
   21 | /*ll fact[N]={1},invfac[N]={1};
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   22 | void factorial()
      | ~~~~~~~~~~~~~~~~             
   23 | {
      | ~                            
   24 |     fact[0]=fact[1]=invfac[0]=invfac[1]=1;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   25 |     for(int i=2; i<N; i++)
      |     ~~~~~~~~~~~~~~~~~~~~~~   
   26 |     {
      |     ~                        
   27 |         fact[i]=(fact[i-1]*i)%mod;
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~
   28 |         invfac[i]=power(fact[i],mod-2);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   29 |     }
      |     ~                        
   30 |     return;
      |     ~~~~~~~                  
   31 | }
      | ~                            
   32 | 
      |                              
   33 | 
      |                              
   34 | int modinv(int a, int x)
      | ~~~~~~~~~~~~~~~~~~~~~~~~     
   35 | {
      | ~                            
   36 |     for (int i = 1; i < x; i++)
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |         if (((a % x) * (i% x)) % x == 1)
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   38 |             return i;
      |             ~~~~~~~~~        
   39 | }*/
      | ~~~                          
   40 | //ll dist(ll x,ll y,ll a,ll b){x-=a; x=power(x,2); y-=b; y=power(y,2); return sqrt(x+y);}
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   41 | string s;
      | ~~~~~~~~~                    
   42 | void printer(string x)
      | ~~~~~~~~~~~~~~~~~~~~~~       
   43 | {
      | ~                            
   44 |      lp(x.size())
      |      ~~~~~~~~~~~~            
   45 |      {
      |      ~                       
   46 |          if(x[i]!='-'){s+=x[i];}
      |          ~~~~~~~~~~~~~~~~~~~~~~~
   47 |      }
      |      ~                       
   48 |      s+='P';
      |      ~~~~~~~                 
   49 | }
      | ~                            
   50 | void dash(int d)
      | ~~~~~~~~~~~~~~~~             
   51 | {
      | ~                            
   52 |     lp(d){s+='-';}
      |     ~~~~~~~~~~~~~~           
   53 | }
      | ~                            
   54 | int main()
      | ~~~~~~~~~~                   
   55 | {
      | ~                            
   56 |     ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   57 |     cout<<setprecision(10);cout<<fixed;
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   58 |     // freopen("triangles.in", "r", stdin); freopen("triangles.out", "w", stdout);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   59 |      int n,ans=0;
      |      ~~~~~~~~~~~~            
   60 |      cin>>n;
      |      ~~~~~~~                 
   61 |      vector<string> v;
      |      ~~~~~~~~~~~~~~~~~       
   62 |      lp(n){string x; cin>>x ; v.pp(x);}
      |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   63 |      sort(v.begin(),v.end());
      |      ~~~~~~~~~~~~~~~~~~~~~~~~
   64 |      for(int i=0;i<n;i++)
      |      ~~~~~~~~~~~~~~~~~~~~    
   65 |      {
      |      ~                       
   66 |          int d=v[i].size();
      |          ~~~~~~~~~~~~~~~~~~  
   67 |           printer(v[i]);
      |           ~~~~~~~~~~~~~~     
   68 |           if(i<n-1)
      |           ~~~~~~~~~          
   69 |           {
      |           ~                  
   70 |               lpj(min(v[i].size(),v[i+1].size()))
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   71 |               {
      |               ~              
   72 |                   if(v[i][j]==v[i+1][j]){v[i+1][j]='-'; d--;}
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   73 |                   else{break;}
      |                   ~~~~~~~~~~~~
   74 |               }
      |               ~              
   75 |               dash(d);
      |               ~~~~~~~~       
   76 |           }
      |           ~                  
   77 |      }
      |      ~                       
   78 |      cout<<s.size()-n<<endl;
      |      ~~~~~~~~~~~~~~~~~~~~~~~ 
   79 |      lp(s.size()){cout<<s[i]<<endl;}
      |      ~~~~~~~~~~~             
printer.cpp:79:6: note: in expansion of macro 'lp'
   79 |      lp(s.size()){cout<<s[i]<<endl;}
      |      ^~
printer.cpp:59:12: warning: unused variable 'ans' [-Wunused-variable]
   59 |      int n,ans=0;
      |            ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Expected EOF
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Expected EOF
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Expected EOF
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Expected EOF
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Expected EOF
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 344 KB Expected EOF
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 67 ms 848 KB Expected EOF
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 165 ms 1544 KB Expected EOF
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 414 ms 2996 KB Expected EOF
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 384 ms 2896 KB Expected EOF
2 Halted 0 ms 0 KB -