Submission #83362

# Submission time Handle Problem Language Result Execution time Memory
83362 2018-11-07T10:50:22 Z heon Programiranje (COCI17_programiranje) C++11
80 / 80
43 ms 11904 KB
#include<bits/stdc++.h>

using namespace std;

int pre[26][50005];

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	string s;
	cin >> s;
	int n = s.size();
	for(int i = 0; i < n; i++){
		if(!i) pre[s[i] - 'a'][i] = 1;
		else{
			pre[s[i] - 'a'][i]++;
			for(int j = 0; j < 26; j++) pre[j][i] += pre[j][i-1];
		}
	}

	int q;
	cin >> q;
	while(q--){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		a--,b--,c--,d--;
		if(abs(a - b) != abs(c - d)) cout << "NE\n";
		else{
			bool ok = 1;
			for(int j = 0; j < 26; j++){
				if(a == 0){
					if(pre[j][b] != pre[j][d] - pre[j][c-1]){
						ok = 0;
						break;
					}
				}
				else{
					if(pre[j][b] - pre[j][a-1] != pre[j][d] - pre[j][c-1]){
						ok = 0;
						break;
					}
				}
			}
			cout << (ok ? "DA\n" : "NE\n");
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 3 ms 760 KB Output is correct
3 Correct 3 ms 884 KB Output is correct
4 Correct 3 ms 1048 KB Output is correct
5 Correct 3 ms 1048 KB Output is correct
6 Correct 35 ms 7332 KB Output is correct
7 Correct 43 ms 8588 KB Output is correct
8 Correct 35 ms 9752 KB Output is correct
9 Correct 36 ms 10892 KB Output is correct
10 Correct 32 ms 11904 KB Output is correct