题解归档 - cf104118K

题解归档 - cf104118K

本文由 cf-code 本地题解库自动归档;公开内容以本地 AC/验证版本为准。

思路

Gym 104118K - Kapitan Amazing

The oily keys are exactly the letters that appear in the password:

  • every oily key must appear at least once;
  • no non-oily key may appear.

So each query is possible iff the set of distinct letters in the query equals the set of * positions on the keyboard.

Complexity: O(total query length).

Checks:

  • official sample 1
  • statement sample 2 reconstructed from PDF logic

代码

来源:problems/cf104118K/solution.cpp

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    vector<string> key(3);
    cin >> key[0] >> key[1] >> key[2];

    string layout[3] = {"QWERTYUIOP", "ASDFGHJKL", "ZXCVBNM"};
    int target = 0;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < (int)key[i].size(); ++j) {
            if (key[i][j] == '*') target |= 1 << (layout[i][j] - 'A');
        }
    }

    int q;
    cin >> q;
    while (q--) {
        string s;
        cin >> s;
        int got = 0;
        for (char ch : s) got |= 1 << (ch - 'A');
        cout << (got == target ? "POSSIBLE" : "IMPOSSIBLE") << '\n';
    }
    return 0;
}
~  ~  The   End  ~  ~


 赏 
感谢您的支持,我会继续努力哒!
支付宝收款码
tips
文章二维码 分类标签:归档TypechoAutoUpload
文章标题:题解归档 - cf104118K
文章链接:https://www.fangshaonian.cn/archives/175/
最后编辑:2026 年 6 月 28 日 19:03 By 方少年
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
(*) 3 + 9 =
快来做第一个评论的人吧~