#23944: 求助~卡在92% 卡#1#3 後面都過了


superuserjoy@gmail.com (summeruserjoy)

學校 : 國立中興大學
編號 : 98294
來源 : [49.217.239.47]
最後登入時間 :
2022-04-05 21:11:31
e289. 美麗的彩帶 -- APCS | From: [140.120.220.28] | 發表日期 : 2021-01-03 21:20

#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(0);
int m,n;
while(cin>>m>>n){
map<string,int> rainbow;
rainbow.clear();
vector<string> colors;
colors.clear();
colors.resize(n);
int colors_over_1 = 0;
int diff_color_amount = 0;
for(int i = 0 ; i < n ; i ++){
cin>>colors[i];
rainbow[colors[i]] += 1;
if(rainbow[colors[i]] > 1){
colors_over_1 += 1;
}
if(!(i < m - 1)){
if(colors_over_1 == 0){
diff_color_amount += 1;
}
rainbow[colors[(i-m+1)]] -= 1;
if(rainbow[colors[(i-m+1)]] == 1){
colors_over_1 -= 1;
}
}

 
}
cout<<diff_color_amount<<endl;
}
}
 
#23947: Re:求助~卡在92% 卡#1#3 後面都過了


superuserjoy@gmail.com (summeruserjoy)

學校 : 國立中興大學
編號 : 98294
來源 : [49.217.239.47]
最後登入時間 :
2022-04-05 21:11:31
e289. 美麗的彩帶 -- APCS | From: [180.204.148.98] | 發表日期 : 2021-01-04 01:50

#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(0);
int m,n;
while(cin>>m>>n){
map<string,int> rainbow;
rainbow.clear();
vector colors;
colors.clear();
colors.resize(n);
int colors_over_1 = 0;
int diff_color_amount = 0;
for(int i = 0 ; i < n ; i ++){
cin>>colors[i];
rainbow[colors[i]] += 1;
if(rainbow[colors[i]] > 1){
colors_over_1 += 1;
}
if(!(i < m - 1)){
if(colors_over_1 == 0){
diff_color_amount += 1;
}
rainbow[colors[(i-m+1)]] -= 1;
if(rainbow[colors[(i-m+1)]] == 1){
colors_over_1 -= 1;
}
}

 
}
cout<<diff_color_amount<<endl;
}
}

沒事了忘了加一個條件XD

 
ZeroJudge Forum