結果

問題 No.2042 RGB Caps
ユーザー uytvccuytvcc
提出日時 2022-08-19 21:59:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 2,149 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 181,276 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-11-16 01:56:07
合計ジャッジ時間 2,864 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void solve()':
main.cpp:71:29: warning: 'minc' may be used uninitialized [-Wmaybe-uninitialized]
   71 |                 ans+=st[minc];
      |                             ^
main.cpp:61:13: note: 'minc' was declared here
   61 |         int minc;
      |             ^~~~
main.cpp:48:16: warning: 'col' may be used uninitialized [-Wmaybe-uninitialized]
   48 |         mp[--a]=col;
main.cpp:44:13: note: 'col' was declared here
   44 |         int col;
      |             ^~~

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define MOD2 998244353
#define INF 1000000007
#define LINF 1000000000000000007LL
#define PI 3.14159265359
#define P pair<ll,ll>
template <typename T>
inline bool chmax(T &a, const T &b){
if(a<b) {a=b; return true;}
else return false;
}
template <typename T>
inline bool chmin(T &a, const T &b){
if(a>b) {a=b; return true;}
else return false;
}
struct Edge{
int to; ll cost; int rev;
Edge(int to, ll cost, int rev) : to(to), cost(cost), rev(rev) {}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g,int from,int to,ll cost,bool revFlag,ll revCost){
g[from].push_back(Edge(to,cost,g[to].size()));
if(revFlag) g[to].push_back(Edge(from,revCost,g[from].size()-1));
}
string st = "RGB";
void solve(){
int n,k;
cin>>n>>k;
map<int,int> mp;
rep(i,k){
int a; char c;
cin>>a>>c;
int col;
if(c=='R') col=1;
if(c=='G') col=2;
if(c=='B') col=3;
mp[--a]=col;
}
string ans="";
vector<int> col(3,0);
int m=1;
bool exist=1;
rep(i,n){
if(mp[i]==0){
m++;
continue;
}
int c=mp[i]-1;
int minc;
rep(j,m){
int cnt=INF;
rep(x,3){
if(chmin(cnt,col[x])) minc=x;
}
if((col[c]<col[0] || col[c]<col[1] || col[c]<col[2]) || (col[0]==col[1] && col[1]==col[2])){
ans+=st[c];
col[c]++;
}else{
ans+=st[minc];
col[minc]++;
}
}
if(col[c]<col[0] || col[c]<col[1] || col[c]<col[2]) exist=0;
m=1;
}
rep(j,m-1) ans += 'R';
if(!exist) cout<<-1<<endl;
else cout<<ans<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout<<setprecision(10)<<fixed;
solve();
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0