1070H - BerOS File Suggestion - CodeForces Solution


brute force implementation *1500

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define int long long 
using namespace std;
int n, q;
string s;
map<string, string> mp;
map<string, int> pos;
map<string, bool> vis;
signed main (){
	cin >> n;
	for (int i = 1; i <= n; ++i){
		cin >> s;
		vis.clear();
		for (int j = 0; j < s.size(); ++j){
			string sa = "";
			for (int k = j ; k < s.size(); ++k){
				sa += s[k];
				if (vis[sa]) continue;
				mp[sa] = s;
				++pos[sa];
				vis[sa] = 1;
			}
		}
	}
	cin >> q;
	while (q --){
		cin >> s;
		if (!mp.count(s)) cout << "0 -" << '\n';
		else cout << pos[s] << ' ' << mp[s] << '\n';
	} 
	return 0;
}
  	 		 		 	 	        			   	


Comments

Submit
0 Comments
More Questions

1396B - Stoned Game
16A - Flag
1056A - Determine Line
670B - Game of Robots
1418C - Mortal Kombat Tower
1382B - Sequential Nim
1272C - Yet Another Broken Keyboard
808A - Lucky Year
1245A - Good ol' Numbers Coloring
58B - Coins
1041C - Coffee Break
507A - Amr and Music
1041D - Glider
1486A - Shifting Stacks
1389B - Array Walk
71B - Progress Bar
701A - Cards
545A - Toy Cars
1538E - Funny Substrings
234A - Lefthanders and Righthanders
1611D - Weights Assignment For Tree Edges
197A - Plate Game
1474A - Puzzle From the Future
6B - President's Office
1405B - Array Cancellation
431C - k-Tree
101A - Homework
1642C - Great Sequence
1523B - Lord of the Values
1406C - Link Cut Centroids