답안 #636647

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
636647 2022-08-29T21:08:16 Z Mr_Ph Lozinke (COCI17_lozinke) C++14
100 / 100
305 ms 16464 KB
///Never gonna give you up.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
using namespace std;
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
const ll mod=(ll)1e9+7;
const ll mod1=998244353;
///the defines :)
#define endl '\n'
#define vi vector<int>
#define vll vector<ll>
#define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
#define all(arr) arr.begin(),arr.end()
#define allr(arr) arr.rbegin(),arr.rend()
#define sz size()
///the end of the defines ;)
void bla()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("notsus.txt","w",stdout);
#endif
}
ll power(ll x,ll y)
{
    if(y==0)
        return 1;
    if(y==1)
        return x%mod;
    ll r=power(x%mod,(y%mod)/2)%mod;
    if(y%2)
        return ((r%mod)*(r%mod)*(x%mod));
    else
        return ((r%mod)*(r%mod));
}
ll lcm(ll a,ll b)
{
    return max(a,b)/__gcd(a,b)*min(a,b);
}
void preprocess(){}
void solve()
{
  int n;
  cin>>n;
  vector<string>arr(n);
  ent(arr);
  sort(all(arr));
  map<string,int>mp;
  int ans=0;
  for(int i=0;i<n;i++)mp[arr[i]]++;
  for(int i=0;i<n;i++)
  {
    mp[arr[i]]--;
    bool valid=true;
    set<string>st;
    for(int j=0;j<arr[i].sz;j++)
    {
      string c="";
      for(int k=j;k<arr[i].sz;k++)
      {
        c+=arr[i][k];
        st.insert(c);
      }
    }
    for(auto i:st)
    {
      ans+=mp[i];
      //cout<<i<<" "<<mp[i]<<endl;
    }
    //cout<<"goodbye"<<endl;
    mp[arr[i]]++;
  }
  cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    preprocess();
    //bla();
    int t=1;
    //cin>>t;
    while(t--)
        solve();
}

Compilation message

lozinke.cpp: In function 'void solve()':
lozinke.cpp:18:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 | #define ent(arr) for(int i=0;i<arr.size();i++)cin>>arr[i];
      |                              ~^~~~~~~~~~~
lozinke.cpp:52:3: note: in expansion of macro 'ent'
   52 |   ent(arr);
      |   ^~~
lozinke.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for(int j=0;j<arr[i].sz;j++)
      |                  ^
lozinke.cpp:65:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |       for(int k=j;k<arr[i].sz;k++)
      |                    ^
lozinke.cpp:60:10: warning: unused variable 'valid' [-Wunused-variable]
   60 |     bool valid=true;
      |          ^~~~~
lozinke.cpp: In function 'void bla()':
lozinke.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen("input.txt","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
lozinke.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen("notsus.txt","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 8 ms 724 KB Output is correct
6 Correct 12 ms 700 KB Output is correct
7 Correct 17 ms 1400 KB Output is correct
8 Correct 28 ms 2208 KB Output is correct
9 Correct 64 ms 2352 KB Output is correct
10 Correct 128 ms 7372 KB Output is correct
11 Correct 105 ms 4220 KB Output is correct
12 Correct 294 ms 16464 KB Output is correct
13 Correct 197 ms 2648 KB Output is correct
14 Correct 229 ms 14896 KB Output is correct
15 Correct 305 ms 16356 KB Output is correct
16 Correct 172 ms 1080 KB Output is correct
17 Correct 56 ms 852 KB Output is correct
18 Correct 37 ms 852 KB Output is correct
19 Correct 203 ms 8500 KB Output is correct
20 Correct 91 ms 980 KB Output is correct