답안 #900253

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900253 2024-01-08T02:43:37 Z kduongnguyen07 Tavan (COCI16_tavan) C++17
80 / 80
0 ms 604 KB
/*
* Author : Duong Nguyen Khanh a.k.a kduongnguyen07
* Date of birth : 15/08/2007
* From Long Chau Sa High School With Luv 💖
* Problem :
*/
#include<bits/stdc++.h>
using namespace std;
//--- INPUT ---//
#define in(x) int x; cin >> x;
// --- LOOPS ---//
#define for1(i,a,b) for (int i = a; i <= b; i++)
#define for2(i,a,b) for (int i = a; i >= b; i--)
#define arrin(a,l,r) for(int i=l;i<r;i++) cin>>a[i]
#define arrout(a,l,r) for(int i=l;i<r;i++) cout<<a[i]<<" "
#define downline cout<<endl
#define sz(s) ((int) ((s).size()))
// --- VECTOR ---//
#define getLOWERBOUND(x, S) (lower_bound(S.begin(), S.end(), x) - S.begin())
#define getUPPERBOUND(x, S) (upper_bound(S.begin(), S.end(), x) - S.begin())
#define UNIQUE(S)           S.erase(unique(S.begin(), S.end()), S.end())
#define vi vector <int> 
#define vll vector <long long> 
#define pii pair<int,int>
#define sort_vec(S)      (sort(S.begin(), S.end()))
#define sort_arr(S, N)    (sort(S + 1, S + N + 1))
#define pb push_back 
// --- PAIR ---//
#define se second
#define fi first
// ---  OPTIMIZE ---//
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int MAXN = 501;
int n, m, k, x, br;
char s[MAXN];
char f[MAXN][MAXN];
int pos[MAXN];
void kduongnguyen07()
{
    cin>>n>>m>>k>>x;
    cin>>s;
    for(int i = 0; i < n; i++)
    {
        if(s[i] == '#')
        pos[br++] = i;
    }
    for(int i = 0; i < m; i++)
        cin>>f[i];
    if(m == 1 && k == 3)
    {
    char started = 'a';
    for(int a = 0; a < 3; a++)
        for(int b = 0; b < 3; b++)
            for(int c = 0; c < 3; c++)
            {
              if(a == b || a == c || b == c) continue;
              if(f[0][a] < f[0][b] && f[0][b] < f[0][c])
              {
                if(x == 1) started = f[0][a];
                if(x == 2) started = f[0][b];
                if(x == 3) started = f[0][c];
              }
            }
    s[pos[0]] = started;
    cout<<s;
  } 
  else if(m == 1)
  {
    sort(f[0], f[0] + k);
    s[pos[0]] = f[0][x - 1];
    cout<<s;
    return ;
  }
  else
  {
    x--;
    for(int i = 0; i < m; i++)
      sort(f[i], f[i] + k);
    for(int i = 0; i < m; i++)
      s[pos[i]] = f[i][0];
    for(int i = m - 1; i >= 0; i--)
    {
      if(x == 0) break;
      int cur = x % k;
      s[pos[i]] = f[i][cur];
      x /= k;
    }
    cout<<s;
  }
}
main()
{    
    faster;
    //freopen("input.inp", "r", stdin);
    //freopen("output.out", "w", stdout);
kduongnguyen07();
return 0;
}

Compilation message

tavan.cpp:92:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   92 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 0 ms 412 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct