Codeforces Round #607 (Div. 2)

A. Suffix Three

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
We just discovered a new data structure in our research group: a suffix three!

It’s very useful for natural language processing. Given three languages and three suffixes, a suffix three can determine which language a sentence is written in.

It’s super simple, 100% accurate, and doesn’t involve advanced machine learning algorithms.

Let us tell you how it works.

If a sentence ends with “po” the language is Filipino.
If a sentence ends with “desu” or “masu” the language is Japanese.
If a sentence ends with “mnida” the language is Korean.
Given this, we need you to implement a suffix three that can differentiate Filipino, Japanese, and Korean.

Oh, did I say three suffixes? I meant four.

Input
The first line of input contains a single integer t (1≤t≤30) denoting the number of test cases. The next lines contain descriptions of the test cases.

Each test case consists of a single line containing a single string denoting the sentence. Spaces are represented as underscores (the symbol “_”) for ease of reading. The sentence has at least 1 and at most 1000 characters, and consists only of lowercase English letters and underscores. The sentence has no leading or trailing underscores and no two consecutive underscores. It is guaranteed that the sentence ends with one of the four suffixes mentioned above.

Output
For each test case, print a single line containing either “FILIPINO”, “JAPANESE”, or “KOREAN” (all in uppercase, without quotes), depending on the detected language.

Example
inputCopy
8
kamusta_po
genki_desu
ohayou_gozaimasu
annyeong_hashimnida
hajime_no_ippo
bensamu_no_sentou_houhou_ga_okama_kenpo
ang_halaman_doon_ay_sarisari_singkamasu
si_roy_mustang_ay_namamasu
outputCopy
FILIPINO
JAPANESE
JAPANESE
KOREAN
FILIPINO
FILIPINO
JAPANESE
JAPANESE
Note
The first sentence ends with “po”, so it is written in Filipino.

The second and third sentences end with “desu” and “masu”, so they are written in Japanese.

The fourth sentence ends with “mnida”, so it is written in Korean.

#include <bits/stdc++.h>
using namespace std;
int t,n;
void solve(string s)
{
    int len=s.length();
    if(s.substr(len-2,2)=="po")
        cout<<"FILIPINO\n";
    else if(s.substr(len-4,4)=="desu"||s.substr(len-4,4)=="masu")
        cout<<"JAPANESE\n";
    else cout<<"KOREAN\n";
}
string s;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>s;
        solve(s);
    }
    return 0;
}

B. Azamon Web Services

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Your friend Jeff Zebos has been trying to run his new online company, but it’s not going very well. He’s not getting a lot of sales on his website which he decided to call Azamon. His big problem, you think, is that he’s not ranking high enough on the search engines. If only he could rename his products to have better names than his competitors, then he’ll be at the top of the search results and will be a millionaire.

After doing some research, you find out that search engines only sort their results lexicographically. If your friend could rename his products to lexicographically smaller strings than his competitor’s, then he’ll be at the top of the rankings!

To make your strategy less obvious to his competitors, you decide to swap no more than two letters of the product names.

Please help Jeff to find improved names for his products that are lexicographically smaller than his competitor’s!

Given the string s representing Jeff’s product name and the string c representing his competitor’s product name, find a way to swap at most one pair of characters in s (that is, find two distinct indices i and j and swap si and sj) such that the resulting new name becomes strictly lexicographically smaller than c, or determine that it is impossible.

Note: String a is strictly lexicographically smaller than string b if and only if one of the following holds:

a is a proper prefix of b, that is, a is a prefix of b such that a≠b;
There exists an integer 1≤i≤min(|a|,|b|) such that ai<bi and aj=bj for 1≤j<i.
Input
The first line of input contains a single integer t (1≤t≤1500) denoting the number of test cases. The next lines contain descriptions of the test cases.

Each test case consists of a single line containing two space-separated strings s and c (2≤|s|≤5000,1≤|c|≤5000). The strings s and c consists of uppercase English letters.

It is guaranteed that the sum of |s| in the input is at most 5000 and the sum of the |c| in the input is at most 5000.

Output
For each test case, output a single line containing a single string, which is either

the new name which is obtained after swapping no more than one pair of characters that is strictly lexicographically smaller than c. In case there are many possible such strings, you can output any of them;
three dashes (the string “—” without quotes) if it is impossible.
Example
inputCopy
3
AZAMON APPLE
AZAMON AAAAAAAAAAALIBABA
APPLE BANANA
outputCopy
AMAZON

APPLE
Note
In the first test case, it is possible to swap the second and the fourth letters of the string and the resulting string “AMAZON” is lexicographically smaller than “APPLE”.

It is impossible to improve the product’s name in the second test case and satisfy all conditions.

In the third test case, it is possible not to swap a pair of characters. The name “APPLE” is lexicographically smaller than “BANANA”. Note that there are other valid answers, e.g., “APPEL”.

#include <bits/stdc++.h>
using namespace std;
int t,n;
string s,s1;
char c[200000];
int v[200000];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>s>>s1;
        int len1=s.length();
        int len2=s1.length();
        int k=-1;
        c[len1-1]=s[len1-1];char ma=s[len1-1];
        int f=len1-1;v[len1-1]=f;
        for(int i=len1-2;i>=0;i--)
            {
                if(s[i]<ma){ma=s[i];f=i;}
                c[i]=ma;v[i]=f;
            }
        for(int i=0;i<len1;i++)
        {
            if(s[i]!=c[i])
            {
                swap(s[i],s[v[i]]);break;
            }
        }
        if(s<s1)
        cout<<s<<endl;
        else cout<<"---\n";
    }
    return 0;
}

C. Cut and Paste

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by si.

There is one cursor. The cursor’s location ℓ is denoted by an integer in {0,…,|s|}, with the following meaning:

If ℓ=0, then the cursor is located before the first character of s.
If ℓ=|s|, then the cursor is located right after the last character of s.
If 0<ℓ<|s|, then the cursor is located between sℓ and sℓ+1.
We denote by sleft the string to the left of the cursor and sright the string to the right of the cursor.

We also have a string c, which we call our clipboard, which starts out as empty. There are three types of actions:

The Move action. Move the cursor one step to the right. This increments ℓ once.
The Cut action. Set c←sright, then set s←sleft.
The Paste action. Append the value of c to the end of the string s. Note that this doesn’t modify c.
The cursor initially starts at ℓ=0. Then, we perform the following procedure:

Perform the Move action once.
Perform the Cut action once.
Perform the Paste action sℓ times.
If ℓ=x, stop. Otherwise, return to step 1.
You’re given the initial string s and the integer x. What is the length of s when the procedure stops? Since this value may be very large, only find it modulo 109+7.

It is guaranteed that ℓ≤|s| at any time.

Input
The first line of input contains a single integer t (1≤t≤1000) denoting the number of test cases. The next lines contain descriptions of the test cases.

The first line of each test case contains a single integer x (1≤x≤106). The second line of each test case consists of the initial string s (1≤|s|≤500). It is guaranteed, that s consists of the characters “1”, “2”, “3”.

It is guaranteed that the sum of x in a single file is at most 106. It is guaranteed that in each test case before the procedure will stop it will be true that ℓ≤|s| at any time.

Output
For each test case, output a single line containing a single integer denoting the answer for that test case modulo 109+7.

Example
inputCopy
4
5
231
7
2323
6
333
24
133321333
outputCopy
25
1438
1101
686531475
Note
Let’s illustrate what happens with the first test case. Initially, we have s= 231. Initially, ℓ=0 and c=ε (the empty string). The following things happen if we follow the procedure above:

Step 1, Move once: we get ℓ=1.
Step 2, Cut once: we get s= 2 and c= 31.
Step 3, Paste sℓ= 2 times: we get s= 23131.
Step 4: ℓ=1≠x=5, so we return to step 1.
Step 1, Move once: we get ℓ=2.
Step 2, Cut once: we get s= 23 and c= 131.
Step 3, Paste sℓ= 3 times: we get s= 23131131131.
Step 4: ℓ=2≠x=5, so we return to step 1.
Step 1, Move once: we get ℓ=3.
Step 2, Cut once: we get s= 231 and c= 31131131.
Step 3, Paste sℓ= 1 time: we get s= 23131131131.
Step 4: ℓ=3≠x=5, so we return to step 1.
Step 1, Move once: we get ℓ=4.
Step 2, Cut once: we get s= 2313 and c= 1131131.
Step 3, Paste sℓ= 3 times: we get s= 2313113113111311311131131.
Step 4: ℓ=4≠x=5, so we return to step 1.
Step 1, Move once: we get ℓ=5.
Step 2, Cut once: we get s= 23131 and c= 13113111311311131131.
Step 3, Paste sℓ= 1 times: we get s= 2313113113111311311131131.
Step 4: ℓ=5=x, so we stop.
At the end of the procedure, s has length 25.

#include <bits/stdc++.h>
using namespace std;
int t,n;
long long x;
string s;
long long ans=0;
const int mod=1e9+7;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        ans=0;
        cin>>x;
        cin>>s;
        long long len=s.length();
        long long ans=len;
        int f=1;
        while(len<x)
        {
            string g="";
            if(s[len-1]>'0'&&len-f>0)
            len+=(long long)(s[f-1]-'0'-1)*(len-f);
            if(f<=len-1&&len-f>0)
             g=s.substr(f,len-f);
            for(int i=1;i<s[f-1]-'0';i++)
                s+=g;
            f++;
        }
        int k=1;
        while(k<=x)
        {
            if(s[k-1]>'0')
            ans+=(long long)(s[k-1]-'0'-1)%mod*(ans-k)%mod;
            k++;
        }
        cout<<ans%mod<<endl;
    }
    return 0;
}

ACM弱校
第一次排名这么靠前 , 未来的路还很长 加油!!!

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值